Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Having an issue, first time user.

Discussion in 'Scripting' started by Hornedronin, Jan 16, 2021.

  1. Hornedronin

    Hornedronin

    Joined:
    Jan 14, 2021
    Posts:
    2
    Just trying to get a handle on coding and I'm getting a pair of errors I can't find a solutions for.

    Errors:
    Assets\PlayerMovement.cs(18,24): error CS0120: An object reference is required for the non-static field, method, or property 'Transform.right'

    Assets\PlayerMovement.cs(20,20): error CS1061: 'CharacterController' does not contain a definition for 'move' and no accessible extension method 'move' accepting a first argument of type 'CharacterController' could be found (are you missing a using directive or an assembly reference?)

    Code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public CharacterController controller;

    public float speed = 12f;


    // Update is called once per frame
    void Update()
    {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = Transform.right * x + transform.forward * z;

    controller.move(move * speed * Time.deltaTime);
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Transform.right
    needs to be
    transform.right


    C# is case sensitive. Transform is a class, whereas transform is the instance of that class that you actually are trying to access.
     
    Hornedronin and Bunny83 like this.
  3. Hornedronin

    Hornedronin

    Joined:
    Jan 14, 2021
    Posts:
    2
    You are a gem thank you
     
  4. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    also
    controller.move()
    should be
    controller.Move()
    that's how it's defined in the Character Controller script.
     
    JoshWindsor and PraetorBlue like this.