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

Increasing Enemy Speed

$
0
0
I have enemy script that includes the speed. I can get the original script to work, but I wanted to add some difficulty to my game. I tried to increase the speed based on the user's score, but now the enemy does not move at all. I have tried several different things and cannot get the enemy to move. The enemy spawns, but just stands still. What am I doing wrong or what could I add to fix this issue? Here's my code: Working Code: using UnityEngine; using System.Collections; public class RightGloves : MonoBehaviour { public GameObject glove; //public Vector3 target; public static float increaseSpeed=0; private float speed; // Use this for initialization void Start () { } // Update is called once per frame void Update () { speed = Random.Range (6, 10); float change = (speed+=increaseSpeed ) * Time.deltaTime; glove.transform.Translate(Vector3.left *change ); Destroy (gameObject,4); } } Non - Working Code: using UnityEngine; using System.Collections; public class LeftGloves : MonoBehaviour { public GameObject glove; //public Vector3 target; public static float increaseSpeed=0; private float speed; private int level=0; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (ScoreManager.scoreCount >= 10000 && ScoreManager.scoreCount < 20000 && level ==0) { level++; speed = (Random.Range (6, 10)) * Time.deltaTime; //float change = (speed+=increaseSpeed ) * Time.deltaTime; glove.transform.Translate(Vector3.right * speed); Destroy (gameObject,4); } if (ScoreManager.scoreCount >= 20000 && ScoreManager.scoreCount < 50000 && level ==1) { level++; speed = (Random.Range (8, 12)) * Time.deltaTime; //float change = (speed+=increaseSpeed ) * Time.deltaTime; glove.transform.Translate(Vector3.right *speed); Destroy (gameObject,4); } if (ScoreManager.scoreCount > 50000 && level ==2) { level++; speed = (Random.Range (10, 14)) * Time.deltaTime; //float change = (speed+=increaseSpeed ) * Time.deltaTime; glove.transform.Translate(Vector3.right *speed); Destroy (gameObject,4); } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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