fix my C# Code for Unity
Budget: $10 – $30 USD
Hello everyone! here's a piece of my code i managed to make work (from several pieces from here and there... i'm not a coder myself) ;
=========================================================================
public Rigidbody Missile; // Prefab of the shell.
public Transform m_FireTransform; // A child of the tank where the shells are spawned.
public float m_LaunchForce = 10f; // The force given to the shell if the fire button is held for the max charge time.
private bool Reload = true;
private void Start()
{
Invoke ("StartIdle",5);
}
private void StartIdle()
{
Reload = false;
}
public void OnTriggerEnter (Collider other)
{
if (other.tag == "Car" && !Reload)
{
StartCoroutine (Fire());
}
}
IEnumerator Fire ()
{
yield return new WaitForSeconds (3f);
Rigidbody shellInstance =
Instantiate (Missile, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;
shellInstance.velocity = m_LaunchForce * m_FireTransform.forward; ;
}
}
===================================================================
It basically waits for a Car to get into the trigger, waits 5s, then shoots.
The problem i get is that it doesn't restart the counter (neither 5 nor 3s) UNLESS i get out and in the trigger another time....
I hope i'm clear enough; waiting for replies :)
=========================================================================
public Rigidbody Missile; // Prefab of the shell.
public Transform m_FireTransform; // A child of the tank where the shells are spawned.
public float m_LaunchForce = 10f; // The force given to the shell if the fire button is held for the max charge time.
private bool Reload = true;
private void Start()
{
Invoke ("StartIdle",5);
}
private void StartIdle()
{
Reload = false;
}
public void OnTriggerEnter (Collider other)
{
if (other.tag == "Car" && !Reload)
{
StartCoroutine (Fire());
}
}
IEnumerator Fire ()
{
yield return new WaitForSeconds (3f);
Rigidbody shellInstance =
Instantiate (Missile, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;
shellInstance.velocity = m_LaunchForce * m_FireTransform.forward; ;
}
}
===================================================================
It basically waits for a Car to get into the trigger, waits 5s, then shoots.
The problem i get is that it doesn't restart the counter (neither 5 nor 3s) UNLESS i get out and in the trigger another time....
I hope i'm clear enough; waiting for replies :)