This commit is contained in:
Gerard Gascón 2025-04-24 14:23:29 +02:00
commit bd5b1556ff
269 changed files with 6249829 additions and 0 deletions

View 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;
}
}
}
}