Hello guys, I have 2 script here:
FlyTarget.js = attach to FPS (It’s a button, FPS will start flying when click)
Colider.js = attach to Tunnel road(have mesh collider,uncheck “Is Trigger”)
The problem is that, i could not uncheck the FlyTarget.js when the FPS enter the Tunnel road. The FPS tagged as “Player”
Colider.js
function OnCollisionEnter (other:Collision)
{
if (other.gameObject.tag == "Player")
{
GameObject.Find("FPS").GetComponent("FlyTarget").enabled = false;
}
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Player");
}
Somebody help me solve this… T.T thanks ya…i start Unity3D 1 month ago
You don’t need to search the player with Find, since it’s referenced by other in OnCollisionEnter. But what’s wrong is the use of quotes around the script name: once compiled, a new type with the script name (without quotes or extension) is created, and this type is what GetComponent looks for.
function OnCollisionEnter (other:Collision)
{
if (other.gameObject.tag == "Player")
{
other.transform.GetComponent(FlyTarget).enabled = false;
}
}
By the way, the gos lines at the end were incredible time consuming and unnecessary.
EDITED: Set the tunnel tag to “Tunnel”, and attach this to the player script:
function OnCharacterControllerHit(other:Collider) // other is the collider hit
{
if (other.tag == "Tunnel") // the tunnel must be tagged "Tunnel"
{
GetComponent(FlyTarget).enabled = false;
}
}