Hello, i have a problem with RigidBody2D ______________________________ #pragma strict var ToucheSol:System.Boolean=false; var AnimePerso:UnityEditor.GameObjectUtility; function Start () { } function Update () { if(Input.GetKeyDown(KeyCode.Space)&& ToucheSol == true){ GetComponent<Rigidbody2D>AddForce(Vector2(0,2000)); // Operator '<' cannot be used with a left hand side of type 'function(System.Type): UnityEngine.Component' and a right hand side of type 'System.Type'. } if(Input.GetKey(KeyCode.RightArrow)){ transform.Translate(Vector2(0.04,0)); } if(Input.GetKey(KeyCode.LeftArrow)){ transform.Translate(Vector2(-0.04,0)); } } function OnCollisionEnter20(Coll:Collision2D){ if(Coll.gameObject.tag == "Sol"){ ToucheSol=true; } } function OnCollisionExit2D(Coll:Collision2D){ if (Coll.gameObject.tag == "Sol"){ ToucheSol=false; } } ___________________________________ Can you help me please? i'm a beginner
The line should be: GetComponent<Rigidbody2D>().AddForce(Vector2(0,2000)); Note the added ().; GetComponent is a method so you need parentheses, and then the dot accesses methods of the object returned by GetComponent.
Thanks very much, this problem is resolved, but one message still say : Error UCE0001: ';' expected. Insert a semicolon at the end. (UCE0001) (Assembly-UnityScript) at GetComponent().<Rigidbody2D>AddForce(Vector2(0,2000)); Juste between C and E of AddForce
No you put them in the wrong place; the angle brackets <> are part of the GetComponent method, not part of the AddForce method. Look at my post and write that exactly.
Okay , i write like you the lines but hmm... 3 news errors :s GetComponent<Rigidbody2D>().AddForce(Vector2(0,2000)); Error BCE0043: Unexpected token: ). Error BCE0044: expecting ), found '.'. Error UCE0001: ';' expected. Insert a semicolon at the end. I'm sorry, i know i'm bad ^^
I don't think just writing Vector2(0,2000) is valid; that's a constructor, so you may need a 'new' keyword in there. More generally, where did you get this code from anyway? You're getting confused by lots of tiny errors, so you probably should look for a new resource with better code.
I follow a video, where everything work exept this command, because the software Unity get udapted( version 4.20 ) , but write vector2(0,2000) work on the video for me
I'm really worried, everytime, the lines with rigidbody is telling a error, is it possible to get a script with the jump please? thanks
Do you need to specify the type of forcemode you are using? I use c# but I'm sure I've done it by specifying the vector & the force mode. From the unity scripting api public function AddForce(force: Vector2, mode: ForceMode2D = ForceMode2D.Force): void; public void AddForce(Vector2 force, ForceMode2D mode = ForceMode2D.Force);