/// <summary> /// /// </summary> void Start() { m_Transform = transform; m_Collider = GetComponentInChildren <Collider>(); m_RigidBody = GetComponent <Rigidbody>(); m_RigidBody.useGravity = false; m_RigidBody.isKinematic = true; m_NextWaypoint = 0; m_Audio = GetComponent <AudioSource>(); m_Audio.loop = true; m_Audio.clip = SoundMove; // abort if no waypoints if (PathWaypoints == null) { return; } // init the hierarchy gameObject.layer = vp_Layer.MovingPlatform; foreach (Transform w in PathWaypoints.transform) { if (vp_Utility.IsActive(w.gameObject)) { m_Waypoints.Add(w); w.gameObject.layer = vp_Layer.MovingPlatform; } if (w.GetComponent <Renderer>() != null) { w.GetComponent <Renderer>().enabled = false; } if (w.GetComponent <Collider>() != null) { w.GetComponent <Collider>().enabled = false; } } // sort the waypoints alphabetically IComparer comparer = new WaypointComparer(); m_Waypoints.Sort(comparer.Compare); // prepare for takeoff if (m_Waypoints.Count > 0) { m_CurrentTargetPosition = m_Waypoints[m_NextWaypoint].position; m_CurrentTargetAngle = m_Waypoints[m_NextWaypoint].eulerAngles; m_Transform.position = m_CurrentTargetPosition; m_Transform.eulerAngles = m_CurrentTargetAngle; if (MoveAutoStartTarget > m_Waypoints.Count - 1) { MoveAutoStartTarget = m_Waypoints.Count - 1; } } }
/// <summary> /// /// </summary> void Start() { m_Transform = transform; m_Collider = GetComponentInChildren<Collider>(); m_RigidBody = GetComponent<Rigidbody>(); m_RigidBody.useGravity = false; m_RigidBody.isKinematic = true; m_NextWaypoint = 0; m_Audio = GetComponent<AudioSource>(); m_Audio.loop = true; m_Audio.clip = SoundMove; // abort if no waypoints if (PathWaypoints == null) return; // init the hierarchy gameObject.layer = vp_Layer.MovingPlatform; foreach (Transform w in PathWaypoints.transform) { if (vp_Utility.IsActive(w.gameObject)) { m_Waypoints.Add(w); w.gameObject.layer = vp_Layer.MovingPlatform; } if (w.GetComponent<Renderer>() != null) w.GetComponent<Renderer>().enabled = false; if (w.GetComponent<Collider>() != null) w.GetComponent<Collider>().enabled = false; } // sort the waypoints alphabetically IComparer comparer = new WaypointComparer(); m_Waypoints.Sort(comparer.Compare); // prepare for takeoff if (m_Waypoints.Count > 0) { m_CurrentTargetPosition = m_Waypoints[m_NextWaypoint].position; m_CurrentTargetAngle = m_Waypoints[m_NextWaypoint].eulerAngles; m_Transform.position = m_CurrentTargetPosition; m_Transform.eulerAngles = m_CurrentTargetAngle; if (MoveAutoStartTarget > m_Waypoints.Count - 1) MoveAutoStartTarget = m_Waypoints.Count - 1; } }