"error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected" (68688)

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?

3 Answers

3

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;

Line 39 should be:

transform.position = transform.rotation * new Vector3(0.0f, 0.0f, -distance) + target.position;

Gah, @Bunny83 beat me to it. :D But you'll also need to change 0.0 to 0.0f, or just 0, because the Vector3 constructor expects floats.

The error message tells you where the problem is in the code.

transform.position = transform.rotation * Vector3(0.0, 0.0, -distance) + target.position;