x


OnTriggerEnter Not Updating?

Okay here is my simple script to detect what plane the character is walking on. The script works and detects the change in plane but does not update, how can I get it to constantly check using on triggerenter, I don't want to put this in the Update function.

function OnTriggerEnter (col : Collider) {
    if (col.tag == "wood")
    {    print("wood");
    }
    if (col.tag  == "forrest")
    {    print("forrest");
    }        }

Thanks

Okay an update now.

> function OnTriggerStay (col :
> Collider) { 
> 
>      if (!col.tag) return;     
> 
>      var floorType : String = col.tag;
> 
>      switch(floorType) {
>          case "wood":
>           if ( Input.GetButtonDown( "Horizontal" ) || Input.GetButtonDown(
> "Vertical" ) ) {
>                 // play wood floor footsteps.
>           audio.clip = (footStepsWood);
>           audio.Play();
>           }else if ( !Input.GetButton( "Horizontal" ) && !Input.GetButton(
> "Vertical" ) && audio.isPlaying ){
>           audio.Pause(); 
>           }
>               break;
>          case "forrest":
>           if ( Input.GetButtonDown( "Horizontal" ) || Input.GetButtonDown(
> "Vertical" ) ) {
>           // play forrest footsteps
>           audio.clip = (footStepsForrest);
>           audio.Play();
>           }else if ( !Input.GetButton( "Horizontal" ) && !Input.GetButton(
> "Vertical" ) && audio.isPlaying ){
>           audio.Pause(); 
>           }
>               break;
>          default: //if the tag is not a floor type
>               break;
>      } }

This script works it changes the sound depending on the area but i have to press one of the input buttons to get it to work. Cant the sound file change on the enter of the triger? so i dont have to press down a button again?

Thanks

more ▼

asked Apr 24 '12 at 12:07 PM

1992christoff gravatar image

1992christoff
18 2 3 4

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x334

asked: Apr 24 '12 at 12:07 PM

Seen: 401 times

Last Updated: Apr 24 '12 at 12:09 PM