How to fix error on this code c# ?

using UnityEngine;
using System.Collections;

public class Raycast3 : MonoBehaviour {
	static float distance3 = 5;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		RaycastHit hit;
		if( Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward)­,hit)){
			distance3 = hit.distance;
	}
}

and here is the error

Assets/Standard Assets/Cameras/Scripts/Raycast3.cs(14,102): error CS1525: Unexpected symbol `’

help please

1 Answer

1

You are missing a closing }

and it should be out hit : if( Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit)){

using UnityEngine; using System.Collections; public class Raycast3 : MonoBehaviour { static float distance3 = 5; // Use this for initialization void Start () { } // Update is called once per frame void Update () { RaycastHit hit; Vector3 fwd = transform.TransformDirection(Vector3.forward)­; if( Physics.Raycast(transform.position, fwd ,hit)) { distance3 = hit.distance; } } } still got the same error

Where's the 'out' as noted above?