x


can i use cube to change position?

dear all.. i have a question, i want change my first person controller change the position when onTriggerEnter(); but not 0. can i use loadlevel? this is the code :

 function OnTriggerEnter(other : Collider){
 if(other.tag == "Player"){
 if(data.tE>=20){
 Application.LoadLevel(0); --> this one
 print("done");
 }
 else{
 data.tE=data.tE+1;
 print(data.tE);
 exGUI.error=data.tE.ToString();
 }}}
can some one help me?
more ▼

asked Aug 03 '12 at 04:44 PM

fadilRaditya gravatar image

fadilRaditya
7 3 7

so u want to change the position of ur char onTrrigerEnter? or u want to load another scene?

Aug 03 '12 at 04:49 PM Mander

for example the my player enter cube that hv function ontriggerenter() when come there i want my player go to other place/not other scent

Aug 03 '12 at 08:30 PM fadilRaditya

add this script to the other object u r touching not your character

function OnTriggerEnter(other : Collider){

gameObject.Find("myPlayer").transform.position = vector3(1,2,3);

}

this would take ur playaer to this position. vector3(1,2,3);

u can place any other gameoobject and take its position and go there too just do something like

gameObject.Find("myPlayer").transform.position=gameObject.Find("otherPlace").transform.position;

Aug 03 '12 at 08:37 PM Mander

sorry to late confirmation. there is error there vector3 unknown identifier

Aug 07 '12 at 01:29 PM fadilRaditya

and when i change v to V it works, but when i hit the cube that have this script there is an error NullReferenceException testChangePosisition.OnTriggerEnter (UnityEngine.Collider other) (at Assets/script/testChangePosisition.js:5)

Aug 07 '12 at 01:35 PM fadilRaditya
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try this

var newPositionOnTriggerEnter = somewhere;

function OnTriggerEnter(other : Collider){

if(other.tag == "Player"){ if(data.tE>=20){ transform.position = newPositionOnTriggerEnter; //Application.LoadLevel(0); --> this one print("done"); } else{ data.tE=data.tE+1; print(data.tE); exGUI.error=data.tE.ToString(); }}}

more ▼

answered Aug 03 '12 at 04:51 PM

Sundar gravatar image

Sundar
581 2 2

ya, but which somewhere?

Aug 03 '12 at 08:29 PM fadilRaditya
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x289
x263
x5

asked: Aug 03 '12 at 04:44 PM

Seen: 328 times

Last Updated: Aug 07 '12 at 01:35 PM