- Home /
2 questions about 2D camera posistioning.
Overview of my game is you have to drag to dodge enemys constantly running at you and each time you do you get a point.
First thing I want to do is set it up so I can have the enemy respawn with a random x between the edges of the screen that works on any device. using UnityEngine; using System.Collections;
public class ResetBadPos : MonoBehaviour {
System.Random r;
int rInt;
int tInt;
System.Random t;
public int points = 0;
void Start () {
r = new System.Random ();
t = new System.Random ();
rInt = Screen.width;
}
// Update is called once per frame
void Update () {
//rInt = r.Next (-15, 15);
tInt = t.Next (30, 90);
Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);
if (transform.position.y > Screen.height){
transform.position = new Vector3 (rInt, tInt, 0);
}
}
The second thing I want to do involves the line of code below and what I want it to do is reset the position when it's below the screen view but my problem is I start it out of view specifically above.
if (transform.position.y > Screen.height){
transform.position = new Vector3 (rInt, tInt, 0);
}
Comment