- Home /
Expression denotes a `method group', where a `variable', `value' or `type' was expected
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Truster : MonoBehaviour {
void Update() {
if (Input.GetKey (KeyCode.LeftControl)){
GameObject.Find("sphere 2").GetComponent.AddRelativeForce(Vector3.down * 2);
}
}
}
Why do I get this error? Expression denotes a method group', where a
variable', value' or
type' was expected
NullReferenceException: Object reference not set to an instance of an object Truster.Update () (at Assets/Scripts/Thruster Scripts/Truster.cs:11)
The problem is, that the thruster cannot have rigidbody. Since if I do that, the whole thing would like "explode" and fly away.
But my sphere is not allowed to get a rigidBody, because than it would explode.
Should I maybe use Angles. And add force to one of the angle's of the white block?
If your sphere doesn't have a Rigidbody on it, then why are you trying to gain access to a component of type Rigidbody on it?
If a GameObject has a rigidbody, then you should isolate your Find/GetComponent to that part of the gameobject(s). If there isn't a Rigidbody whatsoever, then this will never work for all the obvious reasons. It's impossible to start a car without a car, it's no possible to AddRelativeForce to an object that doesn't have the corresponding component.
Answer by Veldars · Apr 03, 2015 at 01:41 PM
I think your call of GetComponent is wrong.
try like this :
GameObject.Find("sphere 2").GetComponent().AddRelativeForce(Vector3.down * 2);
Your answer
Follow this Question
Related Questions
Error cs0119 expression denotes a 'type' where a 'method group' was expected (Audio) 1 Answer
What is typing a variable? Is it assigning the value? 3 Answers
How to change value of var? 1 Answer
How Can I Change GetType() And GetField() And GetValue() ? 2 Answers
Generic Component Declaration 1 Answer