an object reference is required to access non static member error. I'm quite new to unity and c# so I'm sure I'm just not referencing it properly or something but can someone please tell me what I'm doing wrong? I'm trying to add force to a rigidbody.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public GameObject player;
private static Rigidbody2D rb2d;
public int speed;
void Start ()
{
Rigidbody2D rb2d = gameObject.GetComponent();
speed = 0;
player = this.gameObject;
}
void Update()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 moveDirection = new Vector2 (moveHorizontal, moveVertical);
}
public void AddForce(){
Rigidbody2D rb2d = Rigidbody2D.AddForce(moveDirection, ForceMode2D.Force);
}
}
↧