- Home /
Duplicate Question
error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Hello everyone. I have an error and i don't know how can i fix that.
Here is the code!
using UnityEngine;
using System.Collections;
public class CameraTest : MonoBehaviour {
public Transform target;
public float distance = 10.0f;
public float xSpeed = 250.0f;
public float ySpeed = 120.0f;
public float yMinLimit = -20f;
public float yMaxLimit = 80f;
private float x = 0.0f;
private float y = 0.0f;
// Use this for initialization
void Start () {
x = transform.eulerAngles.y;
y = transform.eulerAngles.x;
if (rigidbody)
rigidbody.freezeRotation = true;
}
// Update is called once per frame
public void LateUpdate () {
if (target) {
if(Input.GetMouseButton(1)){
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
}
y = ClampAngle(y, yMinLimit, yMaxLimit);
transform.rotation = Quaternion.Euler(y, x, 0);
transform.position = transform.rotation * Vector3(0.0, 0.0, -distance) + target.position;
}
}
static float ClampAngle (float angle, float min, float max) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
}
and the error is that
error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
if(target and if(rigidbody should probably be something like if(target != null) and also, I don't see a definition for a "rigidbody" variable?
Answer by Bunny83 · Apr 16, 2013 at 12:44 PM
It's C#, so you need the new keyword when you create an object;
transform.position = transform.rotation * (new Vector3(0.0, 0.0, -distance)) + target.position;
or as alternative use one of the constants:
transform.position = transform.rotation * (Vector3.forward* -distance) + target.position;
Answer by Jessy · Apr 15, 2013 at 07:47 PM
The error message tells you where the problem is in the code.
transform.position = transform.rotation * Vector3(0.0, 0.0, -distance) + target.position;
Follow this Question
Related Questions
Quaternion To Matrix conversion failed because input Quaternion is invalid 1 Answer
Making the players head face toward the location of the mouse? 1 Answer
Problem with the rotation of camera in third person 1 Answer
Rotation seems to pass through condition checks 1 Answer
How to make my player look in the direction of its movement? 3 Answers