
The Error is above this sentence
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// add rigidbody 2d and circle collider 2d and change radis to 0.07
public class Player : MonoBehaviour
{
public int power = 500;
public int jumpHeight = 1000;
public bool isFalling = false;
// Use this for initialization
void Start (){
}
// Update is called once per frame
void Update ()
{
GetComponent().AddForce (Vector2.right * power);
}
};
I understand you want to AddForce to a RigidBody2D component, so you can use this :
GetComponent<RigidBody2D>().AddForce (Vector2.right * power);
Now, this is fairly unsafe, to make sure you do have a RigidBody2D component on the same game object, you can use the RequireComponent attribute before the class declaration.
[RequireComponent (typeof (RigidBody2D))]
public class Player : MonoBehaviour
Also, consider storing the component reference. GetComponent has a cost, and it’s better not to use it every frame.
RigidBody2D rb2d;
void Awake ()
{
rb2d = GetComponent<RigidBody2D>();
}
void Update ()
{
rb2d.AddForce (Vector2.right * power);
}