- Home /
Hello can anyone help me i am new in scripting
What i am trying to do is if my player get the key , i want the door open by walking on italt text
Answer by Buckslice · Dec 05, 2017 at 02:08 AM
Not sure how your door is setup, but maybe something like this will work?
if(other.tag == "key1"){
Destroy(other.gameObject);
key1obtained = true;
}
if(other.tag == "door1" && key1obtained){
other.gameObject.GetComponent<DoorScript>().Open();
}
This is my code sir , in the image below that's my code on the key that will destroy, my problem sir is the set up in my door , i put it in the door, but when i walk in there it did'nt destroy
void OnTriggerEnter2D(Collider2D other) {
Player$$anonymous$$anager keyScript = GetComponent<Player$$anonymous$$anager>();
if (other.tag == "Door1" && keyScript.key1obtained == true) {
Destroy (other.gameObject);
},
So is this code you linked here on the key or the door? I think it should be on the key. If its on the door it won't work because it is checking the 'other' gameobject. Is the collider gameobject of the door tagged as "Door1"? It is hard to tell without seeing more of your code but seems like you are close here.
Your answer
Follow this Question
Related Questions
Scan for a variable based upon an integer 2 Answers
Hello guys i am new in unity and i have problem can anyone give me some idea 0 Answers
identifying the index of a gameobject in an array 1 Answer
How to implement tokenization of game characters? 1 Answer
How do I stop moving when attacking? 1 Answer