unity3d - Unity Trigger Collision not working -
i'm working on simple race game in unity3d. player racecar, racing against ai uses waypoints navigate across map. everytime player crosses finish line, lapcounter adds 1 lap. want same happen ai lapcounter, ai crosses finish line, nothing happens. not debug.log shows happening. have tinyurl project here.
below you'll find code that's used trigger lapcounter.
any appreciated.
using unityengine; using system.collections; public class starttrigger : monobehaviour { public light startflash; public int lapcount=0; public int ailapcount=0; public int ctimer=10; public int aictimer=10; public float gametime; public float timedisp; // use initialization void start () { startflash.intensity =0; gametime = 0; } // update called once per frame void update () { gametime+=time.deltatime; } void ontriggerenter( collider mytrigger){ if ((mytrigger.gameobject.tag == "buggy") && (lapcount == 0)) { debug.log ("trigger passed"); lapcount = 1; ctimer = 10; } ctimer -= 2; if ((mytrigger.gameobject.tag == "buggy") && (lapcount == 1) && (ctimer <= 0)) { lapcount = 2; ctimer = 10; } ctimer -= 2; if ((mytrigger.gameobject.tag == "buggy") && (lapcount == 2) && (ctimer <= 0)) { lapcount = 3; ctimer = 10; } if ((mytrigger.gameobject.tag == "buggy") && (lapcount == 3) && (ctimer <= 0)) { application.loadlevel (0); } } void aitriggerenter( collider trigger){ debug.log ("ai trigger passed"); if ((trigger.gameobject.tag == "aibuggy") && (ailapcount ==0)) { ailapcount =1; aictimer=10; } aictimer-=2; if((trigger.gameobject.tag == "aibuggy") && (ailapcount == 1) && (aictimer <= 0)) { ailapcount =2; aictimer=10; } aictimer-=2; if((trigger.gameobject.tag == "aibuggy") && (ailapcount == 2) && (aictimer <= 0)) { ailapcount =3; aictimer=10; } if((trigger.gameobject.tag == "aibuggy") && (ailapcount == 3) && (aictimer <= 0)) { application.loadlevel(0); } } // end ontriggerenter void ongui(){ //playercarscript mycar = mplayer.getcomponent <playercarscript> (); gui.begingroup (new rect (10, 10, 200, 140)); gui.box (new rect (0, 0, 200, 110), "user interface"); gui.textfield (new rect (0, 30, 100, 25), "laps: " + lapcount); gui.textfield (new rect (0, 55, 100, 25), "game time: " + gametime.tostring("f1")); gui.textfield (new rect (0, 80, 100, 25), "timer: " + ctimer); gui.endgroup (); gui.begingroup (new rect (600, 10, 200, 140)); gui.box (new rect (0, 0, 200, 110), "opponent interface"); gui.textfield (new rect (0, 30, 100, 25), "laps: " + ailapcount); //gui.textfield (new rect (0, 55, 100, 25), "game time: " + gametime.tostring("f1")); gui.textfield (new rect (0, 80, 100, 25), "timer: " + aictimer); gui.endgroup (); } void flash(){ startflash.intensity = 8 - startflash.intensity; } }
Comments
Post a Comment