Hi every body in my shooter I’m creating a shield effect but i Have 2 problems
1 my Shield dosen’t work when i I take the powerups
2 During the game every shoot or contact with the enemy destroy the player
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, yMin, yMax; //Screen Boundary dimentions
}
public class Player_Script : MonoBehaviour
{
//Public Var
public float speed; //Player Ship Speed
public Boundary boundary; //make an Object from Class Boundary
public GameObject shot; //Fire Prefab
public Transform shotSpawn; //Where the Fire Spawn
public float fireRate = 0.5F; //Fire Rate between Shots
public GameObject Explosion; //Explosion Prefab
public GameObject restartDialog; //eND gAME
//Private Var
private float nextFire = 0.0F; //First fire & Next fire Time
private bool dead;
void Start () {
restartDialog.SetActive(false);
}
// Update is called once per frame
void Update ()
{
//Excute When the Current Time is bigger than the nextFire time
if (Time.time > nextFire)
{
nextFire = Time.time + fireRate; //Increment nextFire time with the current system time + fireRate
Instantiate (shot , shotSpawn.position ,shotSpawn.rotation); //Instantiate fire shot
audio.Play (); //Play Fire sound
}
}
// FixedUpdate is called one per specific time
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal"); //Get if Any Horizontal Keys pressed
float moveVertical = Input.GetAxis ("Vertical"); //Get if Any Vertical Keys pressed
Vector2 movement = new Vector2 (moveHorizontal, moveVertical); //Put them in a Vector2 Variable (x,y)
rigidbody2D.velocity = movement * speed; //Add Velocity to the player ship rigidbody
//Lock the position in the screen by putting a boundaries
rigidbody2D.position = new Vector2
(
Mathf.Clamp (rigidbody2D.position.x, boundary.xMin, boundary.xMax), //X
Mathf.Clamp (rigidbody2D.position.y, boundary.yMin, boundary.yMax) //Y
);
}
//Called when the Trigger entered
void OnTriggerEnter2D(Collider2D other)
{
//Excute if the object tag was equal to one of these
if(other.tag == "Enemy" || other.tag == "Asteroid" || other.tag == "EnemyShot")
{
Instantiate (Explosion, transform.position , transform.rotation);
//Trigger That its a GameOver
Destroy(gameObject);
restartDialog.SetActive(true);
}
}
public void RestartGame()
{
Application.LoadLevel (Application.loadedLevelName);
}
public void ExitToMenu()
{
Application.LoadLevel ("Menu");
}
//Destroy Player Ship Object
}
This is my player code
#pragma strict
var shieldHealth:int = 3;
var myShield: GameObject;
function takeDamage(){
if(shieldHealth >= 1){
shieldHealth--;
if(shieldHealth == 0){
gameObject.active = false;
GameObject.FindWithTag("Player").SendMessage("resetShield");
shieldHealth = 3;
}
}
}
This is the shield pls could someone help me
Ps :sorry for my english