- Home /
how can i create if statement to setacvite a gameobject, if the 2 game object has been dragged in a same position. i tried event trigger but my scripts didnt work
public void OnDrag (PointerEventData eventData) {
transform.position = Input.mousePosition;
}
Answer by tormentoarmagedoom · Sep 28, 2017 at 09:00 AM
Good day.
I recommend you to use OnTriggerStay() to detect it, and SetActive(false) or Destroy it.
OnTriggerStay will be executed every frame that the collider of the bameobject that contains the script touches the collider of a gameobject called ObjectColliding. An example for OnTriggerStay() :
void OnTriggerStay(Collider NameYouWant)
// NameYouWant is the name you give to the collider that will collide with the GameObject containing this script
{
GameObject ObjectColliding = NameYouWant.gameObject;
//Now you can do what you want, you have the gameObject containing this Script, and the GameObject called "ObjectColliding". You can select what object is colliding using a "if" sentence
if (ObjectColliding.name.contains ("Player"))
{
//Do something
}
}
i tried event trigger but my scripts didnt work, can you give me an example codes?
Acept the answer as correct please :D
Answer by MontyPython · Sep 28, 2017 at 10:50 AM
You could make the 2 gameObjects set a bool to true and have the if statement in Update() to check for the bools to be met.
Your answer
Follow this Question
Related Questions
Why Do My Obstacles Do This In My Object Pooler? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers