I’m trying to make a 3D game like some 2D pixely games you would see in old Arcades. But this script that lets the enemys attack back isn’t working. The enemy ship is just flying somewhere really fast and the Lasers which is what I want them to attack with is spawning a little in front of the enemy ship but the enemy ship is still flying elsewhere. I am only 13 and just started with unity. So I’m not the best debugger so please help me, the code is written in C# (Some people think is hard but I see it easier than Java Script) here it is:
using UnityEngine;
using System.Collections;
public class EnemyAttack : MonoBehaviour {
private float shotInterval = 2;
public GameObject Laser;
private Vector3 laserPos;
public int laserSpeed = 7;
private GameObject Player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
StartCoroutine(MyCounter(10));
StartCoroutine(Shoot());
}
IEnumerator Shoot() {
Vector3 laserPos = transform.position;
laserPos.z -= 2;
Player = UnityEngine.GameObject.FindGameObjectWithTag("Player");
float angle = Vector3.Angle(Player.transform.position, Vector3.right);
Instantiate(Laser, laserPos, Quaternion.Euler(new Vector3(0f, 0f, angle)));
transform.Translate(Player.transform.position * laserSpeed * Time.deltaTime);
yield return new WaitForSeconds(5.0f);
}
IEnumerator MyCounter(int number)
{
int i = 0;
while (i < number)
{
yield return 0; //Wait 1 Frame
yield return new WaitForSeconds(5.0f);
i++;
}
}
}