Commit 164aff47 by Alisa Jung

added shield

Prefab: Scale 0.18 Sprite Renderer for shield.png Box Collider 2D --> Trigger add Shield Script
parent 661dc800
fileFormatVersion: 2
guid: 8c880442b4c4b4240a660c8aa3dd4da4
timeCreated: 1433458310
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -10,6 +10,8 @@ public class PlayerHealth : MonoBehaviour {
private bool alive = true;
public Scrollbar healthbar;
private bool hasShield = false;
// Update is called once per frame
void Update () {
......@@ -27,16 +29,6 @@ public class PlayerHealth : MonoBehaviour {
return currentHealth;
}
/// <summary>
/// Setzt Gesundheit auf bestimmten Wert, aber nicht mehr als maxHealth von dem Player.
/// </summary>
/// <param name="newHealth"></param>
public void setHealth(float newHealth)
{
currentHealth = (newHealth > maxHealth) ? maxHealth : newHealth;
updateHealthbar();
}
//updated die ui healthbar.
private void updateHealthbar()
{
......@@ -52,9 +44,15 @@ public class PlayerHealth : MonoBehaviour {
/// <param name="h"></param>
public void changeHealthBy(float h)
{
if (hasShield && h < 0) return;
currentHealth += h;
if (currentHealth > maxHealth) currentHealth = maxHealth;
updateHealthbar();
}
public void setShield(bool s) {
Debug.Log("Shield " + s + " accepted");
hasShield = s;
}
}
using UnityEngine;
using System.Collections;
public class ShieldScript : MonoBehaviour {
PlayerHealth parentHealth;
public float shieldingTime = 10;
// Use this for initialization
void Start()
{
Invoke("stopShielding", shieldingTime);
}
void OnTriggerEnter2D(Collider2D other)
{
PlayerHealth oldHealth = parentHealth;
if (other.tag == "Player")
{
parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform;
Debug.Log("Set shield from shield");
parentHealth.setShield(true);
}
if (oldHealth != null && oldHealth != parentHealth) oldHealth.setShield(false);
}
void stopShielding()
{
Destroy(gameObject);
}
}
fileFormatVersion: 2
guid: c80458a4e231f0a4189ac96ec41a353b
timeCreated: 1433457908
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f61139bec6a9c264593ee2c032bf7bbb
timeCreated: 1433457789
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment