Hi,
I’m still new to Unity and programming and I’m working on a 3D platformer.
Unfortunately I got a logic issue with a movement script for a moving platform. I wanted the playtform to start mooving when the player is touching it, and to swich its’ direction when it touches a trigger-collider, but somehow my script doesn’t work.
Thank you in advance and sorry for my bad english.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IslandMovement : MonoBehaviour
{
public float MovementSpeed = 2.0f;
public bool Move;
public bool MoveUp;
;
public bool MoveDown;
// Start is called before the first frame update
void Start()
{
Move = false;
}
// Update is called once per frame
void FixedUpdate()
{
if (Move == true)
{
MoveUp = true;
}
if (MoveUp == true)
{
transform.position += transform.up * MovementSpeed * Time.deltaTime;
}
if (MoveDown == true)
{
transform.position += transform.up * -MovementSpeed * Time.deltaTime;
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.Tag == "Player"
{
Move = true;
}
else
{
Move = false;
}
if (collision.gameObject.tag == "MovementTriggerUp")
{
MoveUp = false;
}
if (collision.gameObject.tag == "MovementTriggerDown")
{
MoveUp= true;
}
if (MoveUp == false)
{
if (collision.gameObject.tag == "Player" )
{
MoveDown= true;
}
}
}
}