- Home /
Can you help me solve my C# script error?
Hello again everyone! I'm a javascript person but, I can only script with iTween paths with C# and I don't know much about C#.
I get this weird error that says...
error CS0119:
Expression denotes a "type", where a "variable", "value" or "method group" was expected
...and I know it's referring to the following code:
if(cam.transform.position==Vector3(0,-457.5542,599.0647))
Here's the script I'm having problems with for sake of completeness:
using UnityEngine; using System.Collections;
public class ShowMap1 : MonoBehaviour {
public int time = 5; private bool playClip = false; private bool trig = false; public GameObject cam; public GameObject planet;
void Update () { cam = GameObject.Find("Main Camera"); planet = GameObject.Find("Planet"); if(playClip) { iTween.MoveTo(cam, iTween.Hash("path" , iTweenPath.GetPath("camPath"), "time", time)); playClip = false; } if(trig) { cam.transform.LookAt(planet.transform.position); } if(cam.transform.position==Vector3(0,-457.5542,599.0647)) { Application.LoadLevel(8); } }
void OnTriggerEnter (Collider collider) { cam = GameObject.Find("Main Camera"); if(collider.tag == "Player") { Destroy(GameObject.Find("MiniMapCamera").gameObject); Destroy(cam.GetComponent("SmoothFollow")); playClip = true; trig = true; } } }
Finally someone who actually paste the piece of code that is throwing the error! :)
Answer by Statement · Dec 23, 2010 at 10:50 PM
You must use the new keyword in C# when creating new instances. Also, you're feeding double values where expected single.
// v-- Here! v---------v-- floating point
if (cam.transform.position == new Vector3(0,-457.5542f,599.0647f))
Nothing more than a slight difference in how C# and JS go about its business. Just tuck it to the back of your head if you get errors like those, check if you should use new.
I did that, but I still have errors. If I change the Vector3 statement into shorter numbers, they're gone, but I can't change the numbers becuase my iTween path only brings my camera to (0,-457.5542,599.0647) and not to (0,-460,600) like I set it to be.
@Game Hound: Whenever you ask for help with errors, you need to post the errors; otherwise, all we can do is guess as to what might be wrong (and sometimes we can't even do that). Also, keep in $$anonymous$$d that due to floating-point error, you can't always expect to get exactly the values you're expecting (e.g. 0, -460, 600).
That's because Vector3 operates on singles (float) and not doubles. I have corrected my post. (You need to tuck a "f" at the end of the decimal to denote floating point precision)
Your answer
Follow this Question
Related Questions
What does this mean ? 1 Answer
Having difficulty with semicolons. 2 Answers
Attack a Target (using mouse over?) 1 Answer
HELP BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Vector3'. 1 Answer
Script error. Please Help! 4 Answers