[英]C# error's question as type or namespace issue
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float movementSpeed =100f;
private float verticalDirection;
private Rigidbody rb;
private Animator animator;
// Start is called before the first frame update
public bool IsMoving()
{
return rb.velocity.magnitude > 0.1f;
}
void Awake()
{
rb=GetComponent<Rigidbody>();
animator = GetComponentInChildren<Animator>();
}
private void Update()
{
verticalDirection=Input.GetAxis("Vertical");
verticalDirection=Mathf.Clamp(verticalDirection,0,1);
animator.SetFloat("Speed",verticalDirection);
}
// Update is called once per frame
void FixedUpdate()
{
rb.velocity=Vector3.forward*verticalDirection*movementSpeed*Time.fixedDeltaTime;
}
}
Error1:
Assets\Scripts\PlayerMovement.cs(4,31): error CS0246: The type or namespace name 'MonoBehaviour' could not be found (are you missing a using directive or an assembly reference?)
Error2:
Assets\Scripts\PlayerMovement.cs(10,13): error CS0246: The type or namespace name 'Rigidbody' could not be found (are you missing a using directive or an assembly reference?)
Error3:
Assets\Scripts\PlayerMovement.cs(12,13): error CS0246: The type or namespace name 'Animator' could not be found (are you missing a using directive or an assembly reference?)
Error4:
Assets\Scripts\PlayerMovement.cs(12,13): error CS0246: The type or namespace name 'Animator' could not be found (are you missing a using directive or an assembly reference?)
Error5:
Assets\Scripts\PlayerMovement.cs(6,6): error CS0246: The type or namespace name 'SerializeFieldAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error6:
Assets\Scripts\PlayerMovement.cs(6,6): error CS0246: The type or namespace name 'SerializeField' could not be found (are you missing a using directive or an assembly reference?)
Error7:
Assets\Scripts\Robot.cs(20,13): error CS0246: The type or namespace name 'PlayMovement' could not be found (are you missing a using directive or an assembly reference?)
It is my other code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
//using System.Runtime.Serialization;
//using UnityEngine.UI;
//using System.web.Helpers;
enum RobotStates {Counting,Inspecting}
public class Robot : MonoBehaviour
{
[SerializeField] private float startInspectionTime = 2f;
[SerializeField] private AudioSource jingleSource;
private float currentInspectionTime;
private RobotStates currentState = RobotStates.Counting;
private Animator animator;
private PlayMovement player;
// Start is called before the first frame update
void Start()
{
player=FindObjectType<PlayerMovement>();
animator=GetComponentInChildren<Animator>();
currentInspectionTime = startInspectionTime;
}
// Update is called once per frame
void Update()
{
StateMachine();
}
private void StateMachine()
{
switch(currentState)
{
case RobotStates.Counting:
Count();
break;
case RobotStates.Inspecting:
Inspect();
break;
default:
break;
}
}
private void Count()
{
if (!jingleSource.isPlaying){
animator.SetTrigger("Look");
currentState=RobotStates.Inspecting;
}
}
private void Inspect()
{
if(currentInspectionTime>0)
{
currentInspectionTime -=Time.deltaTime;
if (player.IsMoving())
{
Destroy(player.gameObject);
}
}
else
{
currentInspectionTime=startInspectionTime;
animator.SetTrigger("Look");
jingleSource.Play();
currentState=RobotStates.Counting;
}
}
}
I have 7 error about CS0246.我有 7 个关于 CS0246 的错误。 I used all namespace whatever I can use but it does not work.
我使用了所有我可以使用的命名空间,但它不起作用。 I checked the briket and semicolon all of them but i am not sure why i get error.
我检查了所有的 briket 和分号,但我不确定为什么会出错。 I used **
我用了 **
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using UnityEditor;
using System.Diagnostics;
** Those namespace but it does not work please help me............ **Please note the parenthesis which are causing the issue I have labelled Error Parethesis however I am not entirely sure these are causing the overall issue. ** 那些命名空间但它不起作用请帮助我...... **请注意导致问题的括号我已经标记为 Error Parethesis 但是我不完全确定这些导致了整体问题。
Try to put a space between the using System.Diagnostics;尝试在 using System.Diagnostics 之间留一个空格; and the monobehaviour and also make sure it has the same name as the script file you created.
和 monobehaviour,并确保它与您创建的脚本文件同名。
Reading the error messages:阅读错误信息:
Error2: Assets\Scripts\PlayerMovement.cs(10,13): error CS0246: The type or namespace name 'Rigidbody' could not be found (are you missing a using directive or an assembly reference?)
错误 2:Assets\Scripts\PlayerMovement.cs(10,13):错误 CS0246:找不到类型或命名空间名称“刚体”(是否缺少 using 指令或程序集引用?)
RigidBody
requires a reference to UnityEngine.PhysicsModule
RigidBody
需要引用UnityEngine.PhysicsModule
Error3: Assets\Scripts\PlayerMovement.cs(12,13): error CS0246: The type or namespace name 'Animator' could not be found (are you missing a using directive or an assembly reference?) Error4: Assets\Scripts\PlayerMovement.cs(12,13): error CS0246: The type or namespace name 'Animator' could not be found (are you missing a using directive or an assembly reference?)
Error3:Assets\Scripts\PlayerMovement.cs(12,13):错误 CS0246:找不到类型或命名空间名称“Animator”(是否缺少 using 指令或程序集引用?) Error4:Assets\Scripts\PlayerMovement .cs(12,13):错误 CS0246:找不到类型或命名空间名称“Animator”(是否缺少 using 指令或程序集引用?)
Animator
requires a reference to UnityEngine.AnimationModule
Animator
需要引用UnityEngine.AnimationModule
Error5: Assets\Scripts\PlayerMovement.cs(6,6): error CS0246: The type or namespace name 'SerializeFieldAttribute' could not be found (are you missing a using directive or an assembly reference?) Error6: Assets\Scripts\PlayerMovement.cs(6,6): error CS0246: The type or namespace name 'SerializeField' could not be found (are you missing a using directive or an assembly reference?)
Error5:Assets\Scripts\PlayerMovement.cs(6,6):错误 CS0246:找不到类型或命名空间名称“SerializeFieldAttribute”(是否缺少 using 指令或程序集引用?) Error6:Assets\Scripts\PlayerMovement .cs(6,6):错误 CS0246:找不到类型或命名空间名称“SerializeField”(是否缺少 using 指令或程序集引用?)
SerializeField
requires a using
reference to UnityEngine.CoreModule
SerializeField
需要using
对UnityEngine.CoreModule
的引用
Error7: Assets\Scripts\Robot.cs(20,13): error CS0246: The type or namespace name 'PlayMovement' could not be found (are you missing a using directive or an assembly reference?)
Error7:Assets\Scripts\Robot.cs(20,13):错误 CS0246:找不到类型或命名空间名称“PlayMovement”(是否缺少 using 指令或程序集引用?)
Should this be PlayerMovement
rather than PlayMovement
?这应该是
PlayerMovement
而不是PlayMovement
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.