Hey, I am kinda a beginner at scripting, closer to intermediate. I am getting an error and yes, I know that the script is called Bullet and all that stuff. Here is the error
Assets/Scripts/Guns and Damaging/Gun.js(38,13): BCE0067: There is already a local variable with the name ‘bullet’.
And Here is the code
#pragma strict
var Health : int = 100;
var bullet : GameObject;
var damage : int;
function Update ()
{
if(Health < 0)
{
Die();
}
}
function OnGUI ()
{
GUI.Box(Rect(10,Screen.height - 150, 200, 145), "");
GUI.Label(Rect(20,Screen.height - 140, 180, 125), Health + " / " + "100");
}
function OnTriggerEnter ( hit : Collider )
{
if(hit.gameObject.tag == "RedBullet")
{
bullet = hit.gameObject;
TakeDamage();
}
if(hit.gameObject.tag == "RedBullet")
{
bullet = hit.gameObject;
TakeDamage();
}
}
function TakeDamage()
{
var BulletScript : Bullet = bullet.GetComponent("Bullet");
damage = BulletScript.Damage;
Health -= damage;
}
function Die()
{
Debug.Log("I'm death");
Network.Destroy(gameObject);
var spawnObject : GameObject = GameObject.Find("SpawnManager");
var spawnScript : SpawnManager = spawnObject.GetComponent("SpawnManager");
spawnScript.Dead = true;
}