1
0
This repository has been archived on 2024-09-03. You can view files and clone it, but cannot push or open issues or pull requests.
System-Purge/Assets/Resources/Scripts/MovingPlatform.cs

42 lines
1.0 KiB
C#
Raw Normal View History

using UnityEngine;
using System.Collections;
public class MovingPlatform : MonoBehaviour
{
public float movmentAmount = 10.0f;
public float movementSpeed = 10.0f;
bool dirRight = true;
Vector3 initPos;
void Awake()
{
initPos = transform.position;
}
// Update is called once per frame
void Update ()
{
if (dirRight)
transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);
else
transform.Translate(-Vector2.right * movementSpeed * Time.deltaTime);
if (transform.position.x >= initPos.x + movmentAmount)
dirRight = false;
if (transform.position.x <= initPos.x + -movmentAmount)
dirRight = true;
}
void OnTriggerEnter2D(Collider2D other)
{
2016-01-31 03:21:18 -05:00
if (other.gameObject.tag == "Scene_Object")
other.transform.parent = transform;
}
void OnTriggerExit2D(Collider2D other)
{
2016-01-31 03:21:18 -05:00
if (other.gameObject.tag == "Scene_Object")
other.transform.parent = null;
}
}