- Home /
finish line script
script need correcting for a racing game.
var laps : int;
function OnTriggerEnter (racer : Collider) {
if (racer.Controller.laps < 5) {
laps++;
}
else if (racer.Controller.laps >=5) {
winGame();
}
}
function winGame () {
//do winning stuff here.
Application.LoadLevel("2"); //another level for instance.
}
Assets/startfinishline.js(4,21): BCE0019: 'Controller' is not a member of 'UnityEngine.Collider'. Assets/startfinishline.js(4,68): BCE0019: 'Controller' is not a member of 'UnityEngine.Collider'.
if you could provide some context or more details that might help.
What problems are happening? $$anonymous$$ore information would be helpful.
Answer by terdos · Jun 15, 2011 at 07:42 PM
Assuming Controller is a component attached to the racer's game object you would have to have a GetComponent("Controller"), or something similar, in there somewhere to get a reference to it before you could use it's members.
Answer by Chris D · Jun 15, 2011 at 07:43 PM
The solution to the errors you're getting is that the variable 'racer' is a Collider and there is no property called 'Controller' associated with colliders.
if (racer.Controller.laps < 5) {
This needs to be changed, but without more details, you're not going to get much useful information.
Answer by Bunny83 · Jun 16, 2011 at 02:18 AM
I guess, like terdos said you want to access a component (script) that is called Controller. You should do something like that:
function OnTriggerEnter (racer : Collider) {
var controller = GetComponent.<Controller>();
if (controller.laps < 5) {
laps++;
}
else if (controller.laps >=5) {
winGame();
}
}
Your answer
Follow this Question
Related Questions
flicker car in multiplayer racing car 1 Answer
car racing demo not working 1 Answer
Smoothing collisions with MeshColliders 0 Answers
Win Condition of Racing Level 1 Answer
Does unity 5 has issues in light mapping large sets?? 2 Answers