Moving an Object Using a Trigger
Hello, I wouldn't call myself a Newb since i've had some experience in scripting, but I've encountered a little problem with my moving script. The Script is supposed to move 3 objects put into a mother object downwards to a predefined position, the position IS predefined with an empty object called " Position " I went to the scripting API for a little help and i got it, the script worked without a trigger on it. Thing is I want those "Sticks" may i call them, to move only when i enter a certain area, they stay there forever to watch me play my game so Exiting the Trigger is not a problem here. So, that is the script I got (The mother object is set as the trigger itself)
using UnityEngine;
using System.Collections;
public class Mover : MonoBehaviour {
public Transform target;
public float speed;
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player")
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, target.position, step);
}
}
}
Educate me ._.
Your answer
Follow this Question
Related Questions
Rotate camera when colliding 0 Answers
Rotate an object with Quaternion.Lerp without keeping press a key. 0 Answers
Problems With .rotate behavior 1 Answer
Preventing A Teleporting GameObject From Passing Through Walls 2 Answers
Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one. 0 Answers