x


Scripting & Triggers help

Hey guys, first off thanks for looking.

I'm pretty new to Unity3D and Javascript but I'll explain what I'm trying to do and hopefully someoen can point me in the right direction. I've tried googling and searching answer and I've not found anything that quite helps me but I'll keep looking in the mean time.

Basically I'm making a simple maze which shows different types of interaction for an assignment. I've got cubes which basically fall from the sky and hit the ground and do a camera shake when they do so with the help of iTween. At the moment they do this as soon as it loads up so I thought a trigger would be a good idea so when the player gets to a certain part in the maze the columns would start doing their thing then.

The script I have so far is :

    private var go : GameObject;
private var cam : GameObject;

function Awake(){
    go = gameObject;
    cam = camera.main.gameObject;
}

function Start(){

    while(true){
        OnSelected(true);
        yield new WaitForSeconds(10);
        OnSelected(false);
        yield new WaitForSeconds(1);
    }
}

function OnSelected(on:boolean){

    if(on){
        iTween.rotateFrom(go,{"y":90, "time":1.5, "transition":"easeInExpo"});
        iTween.moveFrom(go,{"y":5, "time":1.5, "transition":"easeInExpo"});
        iTween.colorTo(go,{"r":3, "g":.5, "b":1.2, "time":.3, "delay":1.5});
        iTween.scaleTo(go,{"y":2, "time":2, "delay":2.3});
        iTween.rotateBy(go,{"x":.5, "delay":4.3});
        iTween.moveTo(go,{"y":5, "delay":4.6});
        iTween.moveTo(go,{"y":1.5, "delay":5.8, "transition":"easeInExpo"});
        iTween.shake(cam,{"y":.3, "time":.8, "delay":6.8});
        iTween.moveFrom(go,{"y":1.5, "time":8.5, "transition":"easeInExpo"});
        iTween.moveTo(go,{"y":5, "delay":9});
    }
    else{
    }

}

I have a trigger ready called columnTrigger, this script is currently attached to the cubes so how do I get this script to see if the player has collided with it? Do I need a second script to tell this one when the player has hit it? Or can I use this script to do this job?

It's probably a very basic thing to do but as I said I'm pretty new with this and I'm still trying to grasp this software. Thanks again for looking.

Lev

more ▼

asked Mar 11 '11 at 05:00 PM

Leverage gravatar image

Leverage
1 1 1 4

Sorry, I would help... But I don't know iTween...

-Good Luck

Mar 11 '11 at 05:15 PM AVividLight

The iTween only makes the object move, I just need to get it to do that only when the "Player" has walked through a trigger that is not this object.

Mar 11 '11 at 06:20 PM Leverage
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You don't need a second script. The trigger object will detect the collision just fine:

function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "Player")
{
//make stuff move
}
}
more ▼

answered Mar 11 '11 at 09:05 PM

tool55 gravatar image

tool55
710 1 3 12

Will this work even if the trigger isn't the object? I've made a cube, unticked the material and ticked isTrigger and put it before the corridor where the cube is. Basically I've made a maze and because these cubes make the screen shake I want them to start only when I'm nearer to them so the screen isn't shaking all the time while you're navigating the maze. So basically the object with this script is round the corner with another object that is a trigger is in a different place.

Thanks for the quick reply.

Mar 12 '11 at 12:45 AM Leverage
(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:

x5066
x3453
x981

asked: Mar 11 '11 at 05:00 PM

Seen: 1090 times

Last Updated: Mar 11 '11 at 05:01 PM