Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How can i pause all object in my game ? Why Coroutine cannot pause using TimeScale ? any one help me how to pause this function?

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SimpleEnemy : MonoBehaviour { public Transform[] patrolpoints; int currentPoint; public float speed=0.05f; public float sight=5f; float speedy; Animator anima; public GameObject Anger; // Use this for initialization void Start () { anima = GetComponent (); Anger.SetActive (false); } void Awake() { StartCoroutine("Patrol"); } // Update is called once per frame void Update () { RaycastHit2D hit = Physics2D.Raycast (transform.position, transform.localScale.x * Vector2.right, sight); if (hit.collider != null && hit.collider.tag == "Player") { speedy = speed * 1.25f; anima.SetBool ("run", true); Anger.SetActive (true); } else { speedy = speed; Anger.SetActive (false); anima.SetBool ("run", false); } } IEnumerator Patrol() { while (true){ if (transform.position.x == patrolpoints [currentPoint].position.x) { currentPoint++; } if (currentPoint >= patrolpoints.Length) { currentPoint = 0; } transform.position=Vector2.MoveTowards(transform.position,new Vector2(patrolpoints[currentPoint].position.x,transform.position.y), speedy); if(transform.position.x>patrolpoints[currentPoint].position.x) transform.localScale=new Vector3(-0.5f,0.3f,1); else if(transform.position.x

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>