How do I know I changed the right script.
I have 4 objects which all have an script called "Item" attached.
function OnCollisionEnter(collision : Collision) {
kind = collision.gameObject;
}
function LatenVallen(){
if(kind != null)
{
var fixJoint = kind.GetComponent(FixedJoint);
Destroy(fixJoint);
kind.gameObject.rigidbody.useGravity = true;
grens = false;
script = kind.GetComponent(Item);
script.valtaan = true;
kind = null;
}
How can I change the boolean of Item1 and then use the boolean in Item1.
Currently, after I changed the boolean of Item1, Item3 uses it to activated a function which changes the boolean back to false.
I justed named them Item1, Item2, Item3 and Item4 instead of 4x Item.
If you're not using prefabs but have manually created 4 objects in the editor and then given them the same script, then you can identify them by their name, assuming you've also given them different names.
The Collision-object passed as an argument in OnCollisionEnter contains information on which GameObject you've collided with. Then you can check the name of the GameObjects involved in the collision to see which GameObjects and consequently, which versions of `Item` you're accessing booleans in.
Edit: You're kind of doing that already. If you have
function OnCollisionEnter(collision : Collision) {
kind = collision.gameObject;
if(kind.name == "[Whatever name you've given the first GameObject]")
// If true, you're accessing the first version of Item
}
Hi,
If you have more than one component, use GetComponents ( which returns a list of components) and then in each component you have to maintain a variable to differentiate them somehow and check against that. Else call the method in each.
Bye,
Jean