I am getting errors about Time and Input on Page 235

Hi,

I am getting errors about Time and Input on page 235.

The name ‘Input’ does not exists in current context

The name ‘Time’ does not exists in current context
my Code is as below:

For Pistol.cs

using System.Collections;
using System.Collections.Generic;

public class Pistol : Gun {
override protected void Update() {
base.Update();
// Shotgun & Pistol have semi-auto fire rate
if (Input.GetMouseButtonDown(0) && (Time.time - lastFireTime)
> fireRate) {
lastFireTime = Time.time;
Fire();
}
}
}
and for Gun.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gun : MonoBehaviour {
public float fireRate;
protected float lastFireTime;

// Use this for initialization
void Start() {

	lastFireTime = Time.time - 10;
}


// Update is called once per frame
protected virtual void Update() {
	
}

protected void Fire() {

}

}

I have followed exactly what’s mentioned in the book but not sure why I am getting these errors. Please help.

Please help with this. I am still stucked.

Hey @kunal1784

Could you try adding this to the top of the Pistol script:

using UnityEngine;

Both the Time and Input classes are part of that namespace so that might do the trick.

Cheers!

Thanks buddy, It worked… :slight_smile:

1 Like