Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved How to make a script activation zone?

Discussion in 'Scripting' started by Gamadrila, Mar 26, 2023.

  1. Gamadrila

    Gamadrila

    Joined:
    Sep 5, 2021
    Posts:
    142
    Hello everyone.
    I read about OnTriggerEnter. But I am not using the Rigidbody component. What other ways are there to make a script activation zone?
    I came up with another way. Check in each frame whether the point lies in the circle. Is this method good? Is there a ready-made script with a formula for a circle and a rectangle?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    33,467
    Circle is just distance (Vector3.Distance()) compared to radius.

    Rectangles are just min / max on all the axes. If the Rectangle is not axis aligned you would need to transform the point, perhaps with Transform.TransformPoint(), to match first.

    Experiment in isolation before you try to use it in game.
     
    Gamadrila likes this.
  3. Gamadrila

    Gamadrila

    Joined:
    Sep 5, 2021
    Posts:
    142
    Thanks for the answer. For now, I'll use the circle.