reaching to another script and find out if bool is true or false

Hi

I have an interesting question. I have 1 script called SCRPT. Im using the same scprit for a lot of different piece of model (a box at the moment). Since im using it for more than 1 object i cannot use this method :

if (GameObject.Find("name of the gameobject holding the script with the bool").GetComponent<name of the script holding the bool>().IsLightOn) //will check if true

So i need a method that i reach only the script and object name should be depending on to the selections… If i select first object then it should check a boolean inside of it false or true… How can i do this ? Im trying to make my object stop once it hit to the collider of the other object but since i cannot make a trigger for it i doesnt work…

Any ideas ?

why can you not use OnCollisionEnter()?

if you want the script attached to a specific object you either:

need a reference to the specific object (i.e. the thing you collided with) or
need to use a find function which returns all objects and iterate over the returned list to find the specific one you want (not brilliant method)

GameObject.Find(…) returns the first one it finds and ignores the rest…

Give me a sec i will draw it for you :slight_smile:

Here is how i used the same script for all the objects i have.


The picture below shows the main idea… My object 1 moves towards object 2. Problem is my code is keep updating the coordinate of the second object and i cant make it stop moving… Despite it hits the second object it keep pushing it…

Thats why i cannot give an object name because all using the same script i cannot know which object that im clicking… So i cannot say object 1 or two all i can say object the one i click…

Anyway bcz of the reasons i mentioned up there I need to reach to the bool value from different script… And the information i found doesnt work with my code so far…

Why can’t you just use

objectYouClicked.GetComponent<Script>();

Because i dont know which object i clicked. Its going to be a random object.

Oh also the script that i want to use my code is belong to an empty game object…

Edit: Right now im trying few different method without using collider like that… Im trying to stop my objects when collision happens… I used this code :

this.GetComponent<Rigidbody>().velocity = Vector3.zero;
        this.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;

But didnt work… it still keep going…

If i make the object kinematic it stop moving but then i need to move other game objects and also the same game object to rotate or even translate(maybe move up or down a bit) due to nature of my game… So i cannot use iskinematic either…

I add second object as the child of the other which a bit solved the random rotation but didnt solve the movement

It honestly sounds like you don’t have a good grasp of what you’re doing. At some point you have to know what object you’re dealing with. It’d literally be impossible to do anything before that. Try using terms that are less vague. Instead of saying “the object I select” describe what the player has to actually do to “select” something.