I edited my code to test out the suggestion or as far as I was able to understand it. and came up with the following code (see below). In theory it should find any enemies with the tag of room2 and apply the render and disabling of script. The problem is that it does none of this. This is weird as in other scripts I use the EXACT code but not inside a trigger and it works fine. The Debug.Log of fooObj shows that the objects have been found. I have also tried fooObj.active = false; and that works fine.
My question is: How do I get this to apply the wanted effects? and if able to solve that problem, how would I apply it to only the enemy that collides? As currently that code will effect all with the room2 tag.
function OnTriggerEnter (other: Collider){
if(other.gameObject.tag == "room2"){
var go:GameObject = other.gameObject;
go.GetComponent(NewBehaviourScript).enabled = false;
}}
Your problem I did not think of is that the object inside the collison function is of collider class, meaning it has the members of the the collider class but not those of the actual object. Here I am turning the object of collider type into an actual GameObject, hence having all members.
I tested that one with 2 spheres, each having rigidbody and the collision occurs and the script is disabled.
you are asigning foo0bj to room2 then checkingif foo0bj is == enemy1r2 it will return false every time and you are not assigning collide check out thisthis is the scripting referance to your trigger see if that helps
function OnTriggerEnter (other: Collider){
if(other.gameObject.tag == “room2”){
//Something happen;
//Here you can do whatever you want to the room2 object using
other.gameObject.member = value;
// Here you access and disable a script
other.GetComponent(“ScriptName”).enabled = false;
}
else if(other.gameObject.tag==“OtherTag”){
// Do what you want to the OtherTag object, below I destroy it.
Destroy(other.gameObject);
Destroy(gameObject);
//Above I access the object that holds the script and destroy it
// See the difference to access?
}
}
other is defined by the argument name you are passing (other:Collider)
If I put (hitting:Collider) then it would be