Im following A FPS shooter game tutorial on youtube and ive come in contact with a problem that i dont understand how to fix. in the description of this video he shows the c# based script but when i load i use it , it brings up a bunch of errors that i dont think should be wrong. The Video Shows how to add a script for a weapon pickup.
using System.Collections; using System.Collections.Generic; using UnityEngine; public float TheDistance = PlayerCasting.DistanceFromTarget public GameObject TextDisplay; public GameObject FakeGun; public GameObject RealGun; public GameObject AmmoDisplay; public AudioSource PickUpAudio; // Update is called once per frame void Update () { TheDistance = PlayerCasting.DistanceFromTarget; if(Input.GetButtonDown("Action")){ if(TheDistance <= 2){ StartCoroutine(TakeNineMil()); } } } void OnMouseOver() { if(TheDistance <= 2){ TextDisplay.GetComponent.<Text>.text = "Take 9mm Pistol"; } } void OnMouseExit() { TextDisplay.GetCompenent.<Text>().text = ""; } IEnumerator TakeNineMil () { PickUpAudio.Play(); transform.position = Vector3(0, -1000, 0); FakeGun.SetActive(false); RealGun.SetActive(true); AmmoDispaly.SetActive(true); yield return new WaitForSeconds(0.1f) } } Assets/Scripts/PickUp9mm.cs(6,7): error CS1525: Unexpected symbol `float', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Everything after the "using" statements should be inside a class definition. Did you download/copy-paste this code from somewhere, or did you retype this code from the youtube video? In the latter case, are you sure you didn't accidentally miss a line of code? Edit: To be more specific, after the last using statement, there should be a line that's something like public class PickUp9mm: monobehaviour { Look at the code listing to be sure. It looks like you'll probably have more errors after you fix that, though.
Where are you seeing that code in the video? The author is using .js (Unity Script/Javascript) not .cs in the video that you posted.
Amongst other things, you're missing the class declaration, but there's quite a few errors in the script (e.g. missing ";", probably some missing using statements (e.g. "using UnityEngine.UI;") and there's other stuff that isn't correct as well. For example, something like this won't work at all in C# Code (CSharp): TextDisplay.GetComponent.< Text >.text = "Take 9mm Pistol"; Can you maybe somewhere post the whole project? I could try fixing the file the way I think it should be right, but without having the rest of the classes you're using, it's a bit of a guessing game in some parts...