#pragma strict
var MinSpeed: int ;
var MaxSpeed: int ;
private var currentspeed: int;
private var x: int;
private var y: int;
private var z: int;
function Start () {
currentspeed = Random.RandomRange(MinSpeed, MaxSpeed);
x = Random.RandomRange(-224, 224);
y = 106;
z = 0.0;
transform.position= new Vector3(x,y,z);
}
function Update () {}
public function Setposition(){
var ToMove = currentspeed * Time.deltaTime;
transform.Translate(Vector3.down * ToMove);
if (transform.position.y < -106)
{currentspeed = Random.RandomRange(MinSpeed, MaxSpeed);
x = Random.RandomRange(-224, 224);
y = 106;
z = 0.0;
transform.position= new Vector3(x,y,z);
}
}
Yeah, they are there before I click play but as soon as I click play they disappear, its as if the code is saying destroy yourself straight away instead of saying destroy yourself when hit by projectile.
there is no call to Destroy , what you do is setting the position of the object far away , I’m pretty sure that your object is not destroyed, but you just can’t see it .
try->
function Start () {
currentspeed = Random.RandomRange(MinSpeed, MaxSpeed);
x = Random.RandomRange(-2, 2);
y = 1;
z = 0.0;
transform.position= new Vector3(0,0,0);
}
That code makes the enemy appear in the center of screen. So they appear again but don’t fall randomly and when I change the x and y coordinates in the code they go back to not appearing
If you can move up and down, it’s shouldn’t be difficult to move it left and right , a few things to check ( your game is in 2D with an orthographic camera , so maybe you move it’s on the wrong dimension )
-add a log in your console , to see if you enter in the condition where you move it .
-when you play your game , click on your gameobject and see in the inscpector if the position of your gameobject change.
PS : it’s better if you search by yourself what is wrong , if you are really stuck notify me and I will try to help you .