Quantcast
Channel: Answers by "shriya"
Viewing all articles
Browse latest Browse all 98

Answer by shriya

$
0
0
Hi NickZack, I guess you are new to unity. Issues in your Script: 1)Vector2.left does not exist .For this you should use (-Vector2.right). 2) In your Update function which runs continuously , you are making your object (on which script is attached) move simultaneously to left and up. Is that what you want? Because it will move out of your scene really fast.you should add controls for it like on button press or arrow keys. Or make camera follow object. 3) For comparing a condition you must use "==" & not "="........ "==" means comparing and "=" means assigning value. 4) You are using Translate and translate never reaches exact position. So the condition where you are comparing will never get executed. You should either use less than equal to 0r greater than equal to 5)Your object is never getting stopped. And you are declaring my transform variable and not using it anywhere. I hope I am able to clarify things. Adding a sample script . let me know if it helped you. using UnityEngine; using System.Collections; public class abc : MonoBehaviour { public float bossSpeed = 10f; // Use this for initialization void Start () { print (transform.position);// this is the object position on which script is attached. transform.position = new Vector3 (0, 0,0);// now we are assigning it position (0,0,0) } // Update is called once per frame void Update () { if (Input.GetKey(KeyCode.Space))// on pressing space key your object will move towards left { transform.Translate (-Vector3.right * bossSpeed * Time.deltaTime); } if (transform.position.x <= -2) //checking if object reached -2 in x direction { print("Reached position"); } } }

Viewing all articles
Browse latest Browse all 98

Trending Articles



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