init
This commit is contained in:
commit
bd5b1556ff
269 changed files with 6249829 additions and 0 deletions
51
Assets/Scripts/PlataformaMovil.cs
Normal file
51
Assets/Scripts/PlataformaMovil.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlataformaMovil : MonoBehaviour {
|
||||
|
||||
public Transform target;
|
||||
public float speed;
|
||||
public bool enableOnCollision;
|
||||
|
||||
bool working;
|
||||
|
||||
private Vector3 start, end;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
if (!enableOnCollision){
|
||||
working = true;
|
||||
}
|
||||
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 && working) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.tag == "Player"){
|
||||
if (enableOnCollision){
|
||||
working = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue