- Home /
combine scripts
Hello, I have a script where I have a object follow a path using empty game objects for waypoints. I want to have it so when the game object reaches lets say waypoint 2 a script that will make the object osicalte will start. How would i do this? Here are the two scripts...
MOVE ON PATH SCRIPT
using UnityEngine; using System.Collections;
public class MoveOnPathScript : MonoBehaviour {
public EditorPathScript PathToFollow;
public int CurrentWayPointID = 0; public float speed; private float reachDistance = 1.0f;//distance between center point and path, so really low will make it have sharp and not smoth transitions public float rotationSpeed = 5.0f; public string pathName; Vector3 last_position; Vector3 current_position; void Start () { // PathToFollow = GameObject.Find(pathName).GetComponent<EditorPathScript>(); last_position = transform.position; } // Update is called once per frame void Update () { float distance = Vector3.Distance (PathToFollow.path_objs[CurrentWayPointID].position, transform.position); transform.position = Vector3.MoveTowards (transform.position, PathToFollow.path_objs[CurrentWayPointID].position, Time.deltaTime * speed); //The capsule will look with z axis var rotation = Quaternion.LookRotation(PathToFollow.path_objs[CurrentWayPointID].position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed); if(distance <=reachDistance) { CurrentWayPointID++; } //makes program bounce back if (CurrentWayPointID >= PathToFollow.path_objs.Count) { CurrentWayPointID = 0; } } }
ROTATING SCRIPT
using UnityEngine; using
System.Collections;
public class Rotator_Roll :
MonoBehaviour {
public float _Angle; public float
_Period;//remember T=1/f private float _Time; // Update is called
once per frame void Update() {
_Time = _Time + Time.deltaTime;
float phase = Mathf.Sin(_Time / _Period);
transform.localRotation = Quaternion.Euler(new Vector3(phase *
_Angle,0,0)); } }
ANY help will be super appreciated!
Add comment
1. List item
Your answer
Follow this Question
Related Questions
How can i check and fire an event when the user look at specific object ? 0 Answers
How to get access to C# script in another way. 2 Answers
How do I setup fixed movement between predetermined tiles? 0 Answers
How to make an 2d object always look at the mouse position without using camera. 0 Answers
Quick code help! (c#) 2 Answers