This question was
closed Mar 07, 2018 at 11:20 PM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
kungfubrofist · Mar 07, 2018 at 10:45 PM ·
errorerror message
Getting an error that's seemingly unfixable?,Why am I getting this error?
I'm trying to write a script that let's me pickup a gun in my game but I'm getting an error that I can't seem to diagnose.
The error:
Assets/Scripts/M9Pickup.cs(37,24): error CS0119: Expression denotes a type, where a variable, value or method group was expected
My script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class M9Pickup : MonoBehaviour {
public float TheDistance = PlayerCasting.DistanceFromTarget;
public GameObject TextDisplay;
public GameObject GunPickup;
public GameObject PlayerGun;
public GameObject AmmoDisplay;
public AudioSource PickUpAudio;
void Update () {
TheDistance = PlayerCasting.DistanceFromTarget;
if (Input.GetButtonDown("Action")) {
if (TheDistance <= 2 ) {
StartCoroutine(PickupGun());
}
}
}
void OnMouseOver () {
if (TheDistance <= 2 ) {
TextDisplay.GetComponent<Text>().text = "Take Gun";
}
}
void OnMouseExit () {
TextDisplay.GetComponent<Text>().text = "";
}
IEnumerator PickupGun () {
PickUpAudio.Play();
transform.position = Vector3(0, -1000, 0);
GunPickup.SetActive(false);
PlayerGun.SetActive(true);
AmmoDisplay.SetActive(true);
yield return new WaitForSeconds(0.1f);
}
}
Comment
Best Answer
Answer by meat5000 · Mar 07, 2018 at 11:11 PM
This line?
transform.position = Vector3(0, -1000, 0);
You need new
keyword before Vector3