Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MovingPlatform : MonoBehaviour {
- public GameObject platform; //liikutettava objekti
- public float moveSpeed; //liikkumisnopeus
- public Transform currentPoint; //Senhetkinen lähtöpiste, ei tarvitse itse määrittää
- public Transform[] points; // Array jolla määritetään pisteiden määrä
- public int pointSelection; // Seuraava piste
- // Use this for initialization
- void Start () {
- currentPoint = points[pointSelection]; //mistä platform lähtee
- }
- // Update is called once per frame
- void Update () {
- platform.transform.position = Vector3.MoveTowards(platform.transform.position, currentPoint.position,
- Time.deltaTime * moveSpeed); //itse liikutus-skripti, liikuttaa nykyisestä pisteestä kohti kohdetta
- if(platform.transform.position == currentPoint.position) //jos kohdepiste saavutettu
- {
- pointSelection++; //siirrytään seuraavaan kohteeseen
- if (pointSelection == points.Length) //jos viimeinen piste saavutettu
- {
- pointSelection = 0; //kohteeksi tulee ensimmäinen piste
- }
- currentPoint = points[pointSelection];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement