- Home /
Question by
incitement1 · Feb 17, 2015 at 05:41 PM ·
destroy
Problem with Score when enemy destroyed
Hello, I don'y know if my question will be rejected this time alslo but i continue try gotting some help may be i have an answer. So i have this script attached to my gun wich is a part of my player. i like to ubdate my UI text when the bullet destroy the enemy.
#pragma strict
public var Score : int;
var UIText : UI.Text;
var theBullet : Rigidbody;
var Speed = 20;
var MissileSound : AudioClip;
var CoinSound : AudioClip;
function Start ()
{
UIText.text="0";
}
function Update () {
if(Input.GetButtonDown("Fire2"))
{
var clone = Instantiate(theBullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0,Speed));
Destroy(clone.gameObject, 2);
AudioSource.PlayClipAtPoint(MissileSound, transform.position);
}
}
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.tag == "Coin")
{
Destroy(col.gameObject);
Score ++;
UIText.text=""+Score;
AudioSource.PlayClipAtPoint(CoinSound, transform.position);
}
}
Comment
and this is my enemy script
#pragma strict
//public var score : int;
public var Score : int;
var UIText : UI.Text;
var Health = 100;
function Update () {
if(Health<=0)
{
Dead();
Score ++;
UIText.text=""+Score;
}
}
function ApplyDammage (TheDammage : int)
{
Health -=TheDammage;
}
function Dead(){
if(gameObject.tag == "target")
{
Destroy(gameObject);
}
}
As @tanoshimi says, what's actually going wrong? You are updating the UIText.text. Does that change? Is it rendered onto the camera? You've not really given much information for the community to go on.
(Also, I can't see any other posts from you that got rejected.)
Your answer