everybody. I'm beginner unity user. When i study unity. my C# script file doesn't insert to prefabs. And it return error message : The script don't inherit a native class that can manage a script.
this is my C# script code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class unPlayerMovement
{ private Transform tr; public float moveSpeed = 30.0f; public float rotSpeed = 150.0f; // Start is called before the first frame update void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false;
tr = GetComponent<Transform>(); } // Update is called once per frame void Update() { float h = Input.GetAxis("Mouse X"); float v = Input.GetAxis("Vertical"); Move(); } void Move(float h, float v) { tr.Rotate(0, v * moveSpeed * Time.deltaTime, 0); tr.Translate(0, 0, h * rotSpeed * Time.deltaTime); }
}
And this is my Unity screen. 5 Answers
Just had this issue too. Check the class name is the exact same as the file name, this fixed it for me.
In your case check the class unPlayerMovement is in a file called unPlayerMovement.cs
This is how your whole script should look like. your Move() had an error too[Fixed]. that's probably the reason why unity was not loading the script. Let me know if you need any help :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class unPlayerMovement : MonoBehaviour {
private Transform tr;
public float moveSpeed = 30.0f;
public float rotSpeed = 150.0f;
// Start is called before the first frame update
void Start()
{ Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; tr = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{ float h = Input.GetAxis("Mouse X"); float v = Input.GetAxis("Vertical"); Move(h,v);
}
void Move(float h, float v)
{ tr.Rotate(0, v * moveSpeed * Time.deltaTime, 0); tr.Translate(0, 0, h * rotSpeed * Time.deltaTime);
}
} 0 You need to inherit from MonoBehaviour.
public class unPlayerMovement:MonoBehaviour 1 if you have counter error somewhere, you can see this error. Firstly you should clear any error from console.
Try Deleting unPlayerMovement.cs.meta file ,
worked for me by deleting .cs.meta file