Skip to content
Permalink
4d38e1d4d3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
49 lines (39 sloc) 1.06 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPatrol : MonoBehaviour
{
public bool moveRight;
public static float speed;
public GameObject Ghost;
void Start()
{
speed = (Random.Range(1f, 1.5f));
Rigidbody2D rigidbody = GetComponent<Rigidbody2D>();
rigidbody.velocity = transform.right * speed;
}
void Update()
{
if (moveRight)
{
transform.Translate(2 * Time.deltaTime * speed, 0, 0);
transform.localScale =new Vector3(-1, 1,1);
}
if (moveRight == false)
{
transform.Translate(2 * Time.deltaTime * -(speed*2), 0, 0);
transform.localScale = new Vector3(1, 1,1);
}
}
void OnTriggerEnter2D(Collider2D other) //Pickups
{
if (other.gameObject.CompareTag("turn")) //If you got the key
{
moveRight = false;
}
if (other.gameObject.CompareTag("turnback")) //go right
{
moveRight = true;
}
}
}