- Home /
Question by
0867532 · Aug 10, 2013 at 09:08 PM ·
C# problem: object removing self on start.
using UnityEngine;
using System.Collections;
public class EnemyKillTrigger : MonoBehaviour {
int newscore=100;
public GameObject EnemyObj;
void OnTriggerEnter (Collider col) {
if (col.tag == "Finish")
PlayerMain3000.score=newscore;// if comment this line object dont remove itself:(
Destroy(EnemyObj);
// Debug.Log("killid");
}
}
whats Problem?
btw score diclared like this: public static int score;
Comment
which object is destroyed?
The object with this script or "EnemyObj"?
Best Answer
Answer by YoungDeveloper · Aug 12, 2013 at 01:01 PM
You forgot the brackets 10 to 13. And there is no need to add the gameObject as public, you can get it from col.
int newscore=100;
void OnTriggerEnter (Collider col) {
if (col.tag == "Finish"){
PlayerMain3000.score=newscore;
Destroy(col.gameObject);
Debug.Log("killid");
}
}
@YoungDeveloper That is not necessarily true.
He might want to destroy regardless of the object's tag.
He didn't give enough info to fully understand the question.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111934im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to expose variables in c# according to selected booleans 1 Answer
I can't go to unify wiki 2 Answers
Ref modifier 1 Answer