So, I’ve been following this tutorial (12. Unity3D Gun Tutorial 2.0 - Zombie FPS - YouTube) on Raycast shooting in Unity, and I can’t figure out why this is happening. Here’s my code:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
if (Input.GetButton ("Fire1")) {
}
}
// Update is called once per frame
void Update () {
}
void Fire () {
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
Transform hitTransform;
Vector3 hitPoint;
FindClosestTransform(ray, hitPoint);
}
Transform FindClosestTransform(Ray ray, out Vector3 hitPoint); {
RaycastHit[] hits = Physics.RaycastAll (ray);
Transform closestHit = null;
float distance = 0;
hitPoint = Vector3.zero;
foreach (RaycastHit hit in hits) {
if(hit.transform != this.transform && (closestHit == null || hit.distance < distance)) {
closestHit = hit.transform;
distance = hit.distance;
hitPoint = hit.Point;
}
}
Debug.Log("We just hit: " + closestHit.name + " with a BLANK");
return closestHit;
}
}
Where ever it says “= hit”, whether that be ‘closestHit = hit.transform;’ or ‘distance = hit.distance;’ or ‘hitPoint = hit.Point;’, there’s a red line. It says it’s an unexpected symbol. There’s also one where it says “= Vector3.zero” between the ‘=’ and ‘Vector3’. So, that led me to believe it was just those that were ‘unexpected’. But, when I had looked at my Console, I got tons and tons of Compiler Error that all said the same unexpected symbol thing. This time though, it was with lots of operators. Ex: ‘{ ,= ,; in, ), !=, && ,== ,< , etc. etc.’ Can anyone help? I am a super noob with Unity and C#, as you may have been able to tell.
Unity version: 5.0.2f1 Personal