Search Unity

PLEASE HELP

Discussion in 'Scripting' started by unity_21axelrada0054, Jan 17, 2019.

  1. unity_21axelrada0054

    unity_21axelrada0054

    Joined:
    Jan 17, 2019
    Posts:
    3
    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.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Please post the script, the errors, and what line the console says the errors occur.
     
  3. unity_21axelrada0054

    unity_21axelrada0054

    Joined:
    Jan 17, 2019
    Posts:
    3
    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'
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,631
    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.
     
    Last edited: Jan 17, 2019
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     
    Joe-Censored likes this.
  6. unity_21axelrada0054

    unity_21axelrada0054

    Joined:
    Jan 17, 2019
    Posts:
    3
    he posted a c# script in his comments, its pinned the top
     
    JeffDUnity3D likes this.
  7. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    111
    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):
    1. 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...