Hi,
I’ve been following along with the Merry Fragmas tutorial, but I got stuck on an issue.
( http://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/merry-fragmas-multiplayer-fps )
using UnityEngine;
using System.Collections;
public class PlayerShooting : MonoBehaviour {
public ParticleSystem muzzleFlash;
Animator anim;
public GameObject impactPrefab;
GameObject[] impacts;
int currentImpact = 0;
int maxImpacts = 5;
bool shooting = false;
// Use this for initialization
void Start () {
impacts = new GameObject[maxImpacts];
for(int i = 0; i < maxImpacts; i++)
impacts[i] = (GameObject)Instantiate(impactPrefab);
anim = GetComponentInChildren<Animator> ();
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown ("Fire1") && !Input.GetKey(KeyCode.LeftShift))
{
muzzleFlash.Play();
anim.SetTrigger("Fire");
shooting = true;
}
}
void FixedUpdate()
{
if(shooting)
{
shooting = false;
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 50f))
{
if(hit.transform.tag == "Enemy")
Destroy (hit.transform.gameObject);
impacts[currentImpact].transform.position = hit.point;
impacts[currentImpact].GetComponent<ParticleSystem>().Play();
if(++currentImpact >= maxImpacts)
currentImpact = 0;
}
}
}
}
So that’s the code, now at line 32, I get this error:
“NullReferenceException: Object reference not set to an instance of an object
PlayerShooting.Update () (at Assets/Scripts/PlayerShooting.cs:32)”
I really don’t have a clue as to why this is happening, as I’ve been following along exactly as in the tutorial. If anyone has a clue as to what could be causing this that would help a lot.
If you need info on how the rest of the project is set up, I made no modifications to what is explained in the tutorial. (I was planning on doing that after I finished the tutorial, but first gotta get rid of those errors)