protected virtual void Start() { timer = 0; movementBehaviour = GetComponent <EnemyMovementBehavior>(); color = ColorAttribute.COLOR_TYPE.YELLOW; sr = GetComponent <SpriteRenderer>(); sr.sprite = sprites[3]; color = (ColorAttribute.COLOR_TYPE)UnityEngine.Random.Range(0, 3); if (sr) { switch (color) { case ColorAttribute.COLOR_TYPE.GREEN: sr.sprite = sprites[0]; break; case ColorAttribute.COLOR_TYPE.MAGENTA: sr.sprite = sprites[1]; break; case ColorAttribute.COLOR_TYPE.ORANGE: sr.sprite = sprites[2]; break; } } tag = "Enemy"; orderingLayer = Mathf.RoundToInt(transform.position.y * 100f) * -1; sr.sortingOrder = orderingLayer; }
// Update is called once per frame public IEnumerator SpawnTargets() { // A variable to keep the randomized value of the y axis float RandY = 0; // A variable to keep the randomized value of the time interval float RandTimeInterval = 0; while (!GameOver) { // Randomly selects a number between the two values RandY = Random.Range(yMin, yMax); RandTimeInterval = Random.Range(MinTimeInterval, MaxTimeInterval); // Sets the vector of the target of its movement before spawned in Vector3 Spawn = new Vector3(transform.position.x, RandY, transform.position.z); // The object is spawned in set to the vector and set to the basic rotation GameObject target = Instantiate(TargetRef.gameObject, Spawn, new Quaternion()); // The target is applied with the moving component EnemyMovementBehavior MovingScript = target.GetComponent <EnemyMovementBehavior>(); // The Start Cosine is randomized MovingScript.StartCos = Random.Range(-1, 1); // Waits the time interval before repeating. yield return(new WaitForSeconds(RandTimeInterval)); } }
/// <summary> /// Spawns and instance of an entity. /// </summary> void SpawnInstance() { //Spawn an instance of spawnObject GameObject spawnedInstance = Instantiate(spawnObject, transform.position, transform.rotation); //Set the EnemyMovementBehavior's target to behaviorTarget EnemyMovementBehavior enemyMovementBehavior = spawnedInstance.GetComponent <EnemyMovementBehavior>(); if (enemyMovementBehavior != null) { enemyMovementBehavior.target = behaviorTarget; } }
private void Awake() { _movement = GetComponent <EnemyMovementBehavior>(); }