Permalink
Cannot retrieve contributors at this time
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?
Platformer/Platformer/Assets/EnemyPatrol.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (39 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |