random translation
Hi, I wanted my enemy (that is constantly rotating around a player) move up and down with random intervals between "orbits", so I came up with this code, but it doesn't work. I think the problem is in the transform.translate inside the if statement. I am sorry if it is a silly question, I am just a beginner.
public class BossBehavior : MonoBehaviour {
 public GameObject cube;
 
 private Vector3 middlePosition = new Vector3(8, 0 , 0);
 private Vector3 upPosition = new Vector3(-8, 4, 0);
 private Vector3 downPosition = new Vector3(8, -4, 0);
   
 // Start is called before the first frame update
 void Start()
 {
   transform.position = middlePosition;
    
 }
 // Update is called once per frame
 void Update()
 {
     float rotSpeedBoss = Random.Range(45f, 150f);
     
     int random = Random.Range(1, 7); 
     Debug.Log(random);
  transform.RotateAround(cube.transform.position, Vector3.up, rotSpeedBoss * Time.deltaTime);
     if (random == 1 &&  transform.position.y == 0)
     {
         transform.Translate(upPosition * Time.deltaTime);
     }
     if (random == 2 &&  transform.position.y ==  -4 )
     {
         transform.Translate(middlePosition * Time.deltaTime);
     }
   
     if (random == 3 && transform.position.y == 4)
     {
         transform.Translate(downPosition * Time.deltaTime);
     }
     
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
Limiting the movement of a player object moved by transform.translate (Unity 5) 0 Answers
Moving a 2d object on X axis by transform.translate 0 Answers
Why is transform.translate not working? 4 Answers
My gameObject slows and accelarates alone in a translation supposed to be constant 0 Answers
Moving an object smoothly over predetermined distance without defining begin and end points 0 Answers