Search Unity

trouble with de-bugging

Discussion in 'Scripting' started by EVenus1, Mar 31, 2015.

  1. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    hi every one
    i do not understand what is wrong with my script as it is exactly the same as unity's tutorial's one
    plz help:

    Assets/scripts/PlayerMovement.cs(13,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)'

    thanks Evenus1
     
  2. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    You need to reference the rigid body you want to move.
     
  3. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    here is my script:

    using UnityEngine;
    using System.Collections;

    public class PlayerMovement : MonoBehaviour
    {
    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical=Input.GetAxis("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    Rigidbody.AddForce(movement);
    }


    }
    could u plz tell me which bit to change
     
  4. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    plz help me
     
  5. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
  6. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    this is still very confusing. and i have followed a tutorial that i watched work made by unity so why is it not right.
     
  7. Strategos

    Strategos

    Joined:
    Aug 24, 2012
    Posts:
    255
    Just adjust your code to reference the rigid body on the object, as demonstrated in the example I linked.
     
  8. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  9. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    i don't get it as i don't get c#
     
  10. EVenus1

    EVenus1

    Joined:
    Mar 31, 2015
    Posts:
    16
    thank you all i now understand