Search Unity

Missing a using directive or an assembly reference

Discussion in 'Scripting' started by starguy197, Mar 7, 2014.

  1. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    Here is the script:
    using UnityEngine;
    using System.Collections;

    [RequireComponent(typeof(PlayerPhysics))]
    public class PlayerController : MonoBehaviour {

    // Player Handling
    public float gravity = 20;
    public float speed = 8;
    public float acceleration = 30;
    public float jumpHeight = 12;

    private float currentSpeed;
    private float targetSpeed;
    private Vector2 amountToMove;

    private PlayerPhysics playerPhysics;


    void Start () {
    playerPhysics = GetComponent<PlayerPhysics>();
    }

    void Update () {
    targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
    currentSpeed = IncrementTowards(currentSpeed, targetSpeed,acceleration);

    if (playerPhysics.grounded) {
    amountToMove.y = 0;

    // Jump
    if (Input.GetButtonDown("Jump")) {
    amountToMove.y = jumpHeight;
    }
    }

    amountToMove.x = currentSpeed;
    amountToMove.y -= gravity * Time.deltaTime;
    playerPhysics.Move(amountToMove * Time.deltaTime);
    }

    // Increase n towards target by speed
    private float IncrementTowards(float n, float target, float a) {
    if (n == target) {
    return n;
    }
    else {
    float dir = Mathf.Sign(target - n); // must n be increased or decreased to get closer to target
    n += a * Time.deltaTime * dir;
    return (dir == Mathf.Sign(target-n))? n: target; // if n has now passed target then return target, otherwise return n
    }
    }
    }


    I seriously don't get what's wrong. Been trying to figure this out for an hour.
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    What line is the error on?
     
  3. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    17 apparently
    "private PlayerPhysics playerPhysics;"
     
  4. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    I don't think PlayerPhysics is a UnityEngine class. Where does it come from? Is it a script you made yourself?
     
  5. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
  6. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    The actual error says this: The type or namespace `PlayerPhysics' could not be found. Are you missing a using directive or an assembly reference?
     
  7. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Do you have the file "PlayerPhysics.cs" somewhere in the Assets folder? Missing that file could be a cause of your error.
     
  8. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    I have it in my assets, according to the video, I made a new folder in assets titled "Scripts", and inserted that.
     
  9. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Yeah if it's missing I don't know why it's not complaining on:
    Code (csharp):
    1. [RequireComponent(typeof(PlayerPhysics))]
    If the script is in your Assets folder somewhere try this:

    1. Click on the "Assets" menu in Unity
    2. Select "Refresh"

    I'm not sure what else it could be!
     
    kwesley likes this.
  10. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    That gave me 2 more errors
     
  11. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Is the old error still there? Are the new errors different?
     
    SCHNOOKTHEDUCK likes this.
  12. starguy197

    starguy197

    Joined:
    Dec 6, 2013
    Posts:
    7
    Oh, I re-copied the scripts from the WordPad document. That seemed to do the trick, funny thing is, I originally copied the script from WordPad.
     
    SCHNOOKTHEDUCK likes this.
  13. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Awesome! I'm glad something fixed it! Good luck to you.
     
    SCHNOOKTHEDUCK likes this.
  14. kwesley

    kwesley

    Joined:
    Jul 3, 2015
    Posts:
    1
     
  15. dhallihan

    dhallihan

    Joined:
    Dec 2, 2019
    Posts:
    2
    i have this same message but its 'touch' and 'IMEcompositionmode'. this app is the kart tutorial but it sorta happend out of no where, if you can answer asap that would be quite nice