public class Player : MonoBehaviour
{
// The force which is added when the player jumps
// This can be changed in the Inspector window
public Vector2 jumpForce = new Vector2(0, 300);
// Update is called once per frame
void Update ()
{
// Jump
if (Input.GetKeyUp("space"))
{
GetComponent<Rigidbody2D>= Vector2();
GetComponent<Rigidbody2D>(jumpForce);
}
// Die by being off screen
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
Die();
}
}
// Die by collision
void OnCollisionEnter2D(Collision2D other)
{
Die();
}
void Die()
{
Application.LoadLevel(Application.loadedLevel);
}
}
Please respond as soon as possible
Thanks in advance
You’re only getting components for lines 7 and 8. Also line 7 is not even a valid statement and line 8 you cannot have anything in the enclosing parenthesis when getting a component. Note that the GetComponent method only gets the first component with that specific instance type. Are you trying to make your character jump, or is this a post jumping function?
GetComponent is a method it needs to be followed by () eventually with arguments
the only case i can think of where you could pass arguments to GetComponent would be the none generic form : GetComponent(typeof(Rigidbody2D)) (it only takes a type or a string as argument)
Vector2() is a constructor it is also a method but cannot exist without the new keyword in front of it new specifies that you want memory allocated for the instance returned by the constructor