- Home /
Cannot convert `lambda expression' to non-delegate type `bool'
So i have this code that shoots bullets, but now i want to add a timer so the player can't spam that much bullits.
public class Shooting : MonoBehaviour {
public float speed = 20f;
public Rigidbody projectile;
float timer = 0f;
void Update ()
{
if (Input.GetButton("Fire1"))
{
if (timer <= 1)
{
//Timer Ini
timer = 5;
//Shooting
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * speed);
}
}
if (timer => 4)
{
timer =-1;
}
}
}
this is what i did, could anyone tell me how to correct this, or how to do it the right way, i'm pretty new :)
Thanks in advance!
Bram.
Comment
Best Answer
Answer by whebert · Mar 22, 2013 at 12:27 AM
Change line 22 to
if (timer >= 4)
The '=>' is used for lambdas (anonymous functions) in C#.
With respect to your timer, if your timer is supposed to be in seconds, you might want to use Time.deltaTime to count down with. Something like:
if (Input.GetButton("Fire1") && timer <= 0)
{
//Timer Ini
timer = 5;
//Shooting
Rigidbody clone;
clone = Instantiate(projectile, transform.position,transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * speed);
}
// Always have timer counting down
timer -= Time.deltaTime;