- Home /
Show points text on collision
Hello everyone. I'm creating a 2d shooter. I am trying to briefly display some points text when the player collects a powerup. I created a plane and applied a Transparent/diffuse material to it that says '100 pts'. Now when the player collides with the powerup I want to destroy the powerup, instantiate the '100 pts' plane, wait 2 seconds then destroy the plane.
The problem is that with my code I destroy the gameObject (the powerup) so the code to destroy the plane isn't run. How can I fix this?
 var crateCollectionSnd:GameObject;
 var minesCollected:GameObject;
 
 function Update () {
     
 }
 
 function OnTriggerEnter(col:Collider){
     if(col.gameObject.tag == "Player"){
         GameObject.Find("PlayerPrefab").GetComponent(FireScript).Mines();
         Instantiate(crateCollectionSnd, transform.position, transform.rotation);
         var cloneMinesCollected = Instantiate(minesCollected, transform.position, Quaternion.Euler(Vector3(0,180,0)));
         Destroy(gameObject);
         yield WaitForSeconds(2);
         Destroy(cloneMinesCollected);
     }else if(col.gameObject.tag == "Bullet" || col.gameObject.tag == "EnemyBullet"){
         Destroy(gameObject);
     }else if(col.gameObject.tag == "Enemy"){
         Destroy(gameObject);
     }
 }
SOLVED
 var crateCollectionSnd:GameObject;
 var minesCollected:GameObject;
 
 function Update () {
     
 }
 
 function OnTriggerEnter(col:Collider){
     if(col.gameObject.tag == "Player"){
         GameObject.Find("PlayerPrefab").GetComponent(FireScript).Mines();
         Instantiate(crateCollectionSnd, transform.position, transform.rotation);
         var cloneMinesCollected = Instantiate(minesCollected, transform.position, Quaternion.Euler(Vector3(0,180,0)));
         renderer.enabled = false;
         yield WaitForSeconds(2);
         Destroy(cloneMinesCollected);
         Destroy(gameObject);
     }else if(col.gameObject.tag == "Bullet" || col.gameObject.tag == "EnemyBullet"){
         Destroy(gameObject);
     }else if(col.gameObject.tag == "Enemy"){
         Destroy(gameObject);
     }
 }
You can't put a yield statement into an OnTriggerEnter function! Are you sure that's working?
Seems to. I even made the points float upward for the 2 seconds until it's destroyed. Is there a better way to do this?
Nah that seems ok. I'm just surprised you can suspend operation like that... must be a Javascript thing.
i don't think its a .js thing i think its a Unity Engine thing that allows it to work.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                