using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
void Movement()
{
if (Input.GetKey("up"))
{
transform.Translate(0, 1, 0);
if (transform.position.y > 175)
transform.Translate(0, -1, 0);
}
if (Input.GetKey("down"))
{
transform.Translate(0, -1, 0);
if (transform.position.y < 5)
transform.Translate(0, 1, 0);
}
if (Input.GetKey("right"))
{
transform.Translate(1, 0, 0);
if (transform.position.x > 115)
transform.Translate(-1, 0, 0);
}
if (Input.GetKey("left"))
{
transform.Translate(-1, 0, 0);
if (transform.position.x < 5)
transform.Translate(1, 0, 0);
}
}
void Start () // Use this for initialization
{
}
void update () // Update is called once per frame
{
Movement();
}
}
And Visual Studio compiles it with no problem, but when I go into Unity, I get warnings about missing script on this behaviour. How can I fix this?
That error has nothing to do with the script’s content. Generally it means you renamed a file or altered the file/folder structure outside of unity and it can’t find the file it’s expecting…
Do you have any errors in the console? In some cases even encountering another script with an error can create issues. However, as @LeftyRighty said, you may have a misnamed script. If your script is named player but your class is Player for example, that can create the issue.
Hello! What if the script in question, was made by Selecting an Object , clicking Add Component and New Script, then PASTING in and saving in the project Assets/Scripts folder?
SO, HOW CAN A SCRIPT BE MISSING FROM AN OBJECT, OR MISNAMED, IF ONE MADE IT ON THE OBJECT ITSELF TO BEGIN WITH? I’m posting my whole relevant problem below, I see the VAST Majority of questions here go unanswered for as long as 6 years, so I think i should paste this in as many places as possible until that one person in 5 billion that like to share info might see it,…
QUESTION:
I Asked for help , got sent a script. (Doesn’t work…), Came with a Single Quarter-Sentence of instruction (Didn’t help…)
I am SIMPLY trying to MOVE an OBJECT with the OCULUS TOUCH CONTROLLERS. Using 3-axis control, LIKE IN AIRCAR Roll/Pitch/Turn,… After a literal year of asking finally someone on the OCULUS site sent the following script and said as the only instruction:
“Attach to gameobject, select handedness, run.”
Of course it does not work ,… I do not even know how to ‘select handedness’, perhaps some day I will be psychic but not yet!..
Here is the ‘script’ as posted… I will paste the errors I am getting and the steps I took below it:
using System.Collections; using System.Collections.Generic; using UnityEngine;
Here is what I did with this mysterious unexplained, un- ‘commented’ script:
I create a New Unity Project and import Oculus Utilities.
I create a cube, I drag in OVR Camera Rig make it a child of the cube…
I select Cube, add component New Script and paste in your text in Visual Studio. I save the file as fly.cs
I set player setting for VR Enabled and Oculus (No open VR)
I run the game window, try every single button and grips etc on each oculus controller, Nothing at all,.
So, That’s where i’m at, I look at the Cube inspector, it does say at the top of the Script Component entry ‘NOTHING SELECTED’ (???) The CUBE IS SELECTED!! The errors I get are:
The referenced script on this Behaviour is missing! (referenced Script? I only have one Script and it’s fly.cs … It is Definately in the Project Folder, That where I created it, as you can see above, I addeda ‘new script’ the the cube, then saved it in Assets/Scripts)
The referenced script on this Behaviour (Game Object ‘Cube’) is missing!
What is this ‘Referenced Script’? I only HAVE one SCRIPT,… It is most certainly IN THE PROJECT FOLDER!! ??? I will attach a screen grab, of the Inspector and the Console,. http://tinypic.com/r/5n84fp/9
You have to have the monobehaviour class named as the filename in Unity. Either you should call your file InputEx.cs or should have fly class in the file.
Doesn’t matter how you create it. If your file name is different from the script name itself, it can’t find it.
As @ posted.
Your filename is fly.cs
Your script name is InputEx (the class)
They don’t match. It’s like making a reservation at a restaurant and telling them your name is Tom and when you show up, your ID says your name is Bill.
It may seem that the vast majority of questions here go unanswered when you don’t read or understand the comments that answer them. In this case the answer was posted in the first comment and again restated by the OP in the comment right above yours. Script names matter for Monobehaviour scripts.
Also use Code tags when posting code. It is described in the sticky thread at the top of this forum.