Am looking to for a concept to spawn enemies in a random position on screen. My game is a 3D space ship game where the player can yaw,strafe move around the 3d environment. However I have created a little script for the individual enemies. But I want to create a script in which the enemies will be spawned on different location on screen wherever the player moves. I have enemy spaceship, space obstacles and satellites. All these three enemies should be spawned on a random location where the player moves and disappear after some time. Thanks in advance
Enemy Script
{
public Transform target;
public float maxRange;
public float minRange;
public float rotationSpeed;
public float speed;
private bool follow; // Follow Enemy Switch
void FixedUpdate()
{
Attack();
}
private void Attack() // Enemy Attack Function
{
if((Vector3.Distance(transform.position,target.position)minRange))
{
follow = true; // Enemy Switch Enabled
}
if(follow) // On enemy Switch Enabled
{
transform.LookAt(target);// Locking the target
transform.Translate(Vector3.forward *speed* Time.deltaTime);// Forward Motion
transform.Rotate(0,90,0); // Gimber Lock
}
}
}
↧