I’m just trying to do a simple trigger for an animation. Mouse is clicked, function executes, boolean gets set to something, causes animation to fire. Except, I keep getting an error message of the type that is in the topic name.
I have no clue what the hell is going on, since I’ve used this method a billion times before, suddenly Unity seems to have gone crazy and forgotten what it can do.
Here’s the code, hope it helps.
using UnityEngine;
using System.Collections;
public class GunControl : MonoBehaviour {
public GUITexture crosshair;
private float fireRate = 1.0f;
private float cooldown = 0f;
float range = 75.0f;
private Ray shot;
private RaycastHit shotInfo;
private bool isHolstered = true;
Animator anim;
// Use this for initialization
void Awake() {
anim = GetComponent<Animator>();
}
void FixedUpdate () {
cooldown -= Time.deltaTime;
anim.SetBool("isShooting", true);
if(Input.GetKeyDown(KeyCode.Q))
{
if(isHolstered) {
isHolstered = false;
crosshair.enabled = true;
} else {
isHolstered = true;
crosshair.enabled = false;
}
}
if (Input.GetMouseButton(0) && cooldown <= 0 && !isHolstered)
{
shot = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
Physics.Raycast(shot, out shotInfo, range);
cooldown = fireRate;
// Instantiate shot effect here ->
// Debug and test code
GameObject go = shotInfo.collider.gameObject;
Debug.Log("Hit Object name " + go.name);
}
}
}