init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
42
Assets/Scripts/MovingPlatform.cs
Normal file
42
Assets/Scripts/MovingPlatform.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MovingPlatform : MonoBehaviour {
|
||||
|
||||
public Transform target;
|
||||
public float speed;
|
||||
public bool i;
|
||||
private Vector3 start, end;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
if(target != null) {
|
||||
target.parent = null;
|
||||
start = transform.position;
|
||||
end = target.position;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (target != null && !i) {
|
||||
float fixedSpeed = speed * Time.deltaTime;
|
||||
transform.position = Vector3.MoveTowards(transform.position, target.position, fixedSpeed);
|
||||
}
|
||||
|
||||
if (transform.position == target.position){
|
||||
target.position = (target.position == start) ? end : start;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision){
|
||||
if(collision.gameObject.tag == "Player"){
|
||||
i = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue