- Home /
Question by
Adonnus100 · Aug 28, 2013 at 02:19 AM ·
ontriggerenter
Making an Object Move on Trigger Enter
Hello, I am trying to make my object (Throne) move when my player enters a certain trigger zone, however I have no idea how to do this. Also, when I enter the second tigger zone (for the throne, not the map) I collect the map...
This is my script so far:
Player Collisions
var mapCollect : AudioClip;
var mapTex1 : GUITexture;
function Start () {
guiTexture.enabled = true;
}
function OnTriggerEnter(collisionInfo : Collider){
audio.PlayOneShot(mapCollect);
Destroy(collisionInfo.gameObject);
Instantiate( mapTex1 );
}
@script RequireComponent (AudioSource)
Throne Triggerer (which do I apply this as a component to?)
var pointB : Vector3;
var pointC : Vector3;
var throneMove = false;
var other;
function OnTriggerEnter () {
if(other.tag == "Player")
{ throneMove = true;}
}
function Update () {
var pointA = transform.position;
while (true) {
yield MoveObject(transform, pointA, pointB, 3.0);
yield MoveObject(transform, pointB, pointC, 3.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 0.5/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
Comment
Answer by screenname_taken · Aug 30, 2013 at 01:12 PM
At the ontriggerenter function you should put other : Collider inside the brackets. Make it OnTriggerEnter(other : Collider) {
}
Your answer