Hey!
Im making a platformer and i want to make a moving platform. I know how to do it with animations, but i have to do an animation for every object so i got an script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformMovement : MonoBehaviour
{
public bool upordown = true; // true is up false is down;
public float speed = 2;
public Transform Platform;
public int smallorbig = 0; // 0 is off 1 is small and 2 is big
public float timetim = 3f;
public float timetim2 = 3f;
void Start()
{
}
void Update()
{
if (smallorbig == 1)
{
timetim -= Time.deltaTime;
if (timetim <= 0f)
{
transform.position += new Vector3(0, speed * Time.deltaTime, 0);
upordown = true;
}
if (timetim > 0f)
{
transform.position += new Vector3(0, -speed * Time.deltaTime, 0);
}
if (timetim <= -3f)
{
timetim = timetim2;
}
}
}
}
and it moves it 1 time perfectly but at some point it sets the timetim to 4 so it starts moving more down than up and i dont want that my brain is starting to hurt so yeah in conclusion its a moving platform that works 1 time and then it sets the timer variable to 4 so it goes more down than up