Hello all,
Having a bit of touble here, Im doing a simple game of shooting gallery game. I have trouble with my prefabs.
When I click on one of my prefabs to destroy it, all the other prefab destroy as well. How to I solve this problem. I want the object that I click destroy, not all of them.
Below is my script:
using UnityEngine;
using System.Collections;
public class Puzzle01_Roach : MonoBehaviour {
public int fHealthAmount;
public int iDamage;
public float fHealth;
public float fHealthColor;
public tk2dSprite sColor;
public GameObject gRoach;
public GameObject gPartical;
bool isDead;
float t;
public Camera cCamera;
Ray rRay;
RaycastHit rRayHit;
// Use this for initialization
void Start ()
{
fHealth = fHealthAmount;
isDead = false;
gPartical.SetActive (false);
gRoach.SetActive (true);
}
// Update is called once per frame
void Update ()
{
rRay = cCamera.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButton (0))
{
if (Physics.Raycast (rRay, out rRayHit, 100))
{
if (rRayHit.collider.gameObject.tag == "tRoach")
{
fHealth -= iDamage;
}
}
}
if (fHealth < 1)
{
gPartical.SetActive (true);
gRoach.SetActive (false);
isDead = true;
}
if (isDead)
{
t += Time.deltaTime;
if (t > 1f)
{
Destroy (this.gameObject);
}
}
fHealthColor = fHealth / 100;
sColor.color = Color.Lerp (Color.red, Color.white, fHealthColor);
}
}
thank you.