[当我创建(添加组件)它被阻止并且无法编辑时,我需要速度和控制器设置!我也有错误

问题描述 投票:0回答:1

我必须统一制作一个游戏,所以我决定制作一个arpg游戏,我在youtube上找到了一个指南,并开始制作该游戏,当我单击添加组件并创建一个不需要语言的新脚本时, (我安装了atom和VS),并且在创建此脚本后,该脚本已被锁定,只有打开它我才能对其进行编辑或执行任何操作。

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


    public class ClickToMove : MonoBehaviour
    {
            public float speed;
            public CharacterController contoller;
            private Vector3 position;

            public AnimationClip run;
            public AnimationClip idle;
        // Use This for initialization
        void Start()
        {
          position = transform.position;
        }
        // Update is called once per frame
        void Update()
        {
          if(Input.GetMouseButton(0))
          {
            //Locate where the player clicked on the terrain
            locatePosition();
          }
          //Move the player to the position
          moveToPosition();
        }

        void locatePosition()
        {
          RaycastHit hit;
          Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

          if(Physics.Raycast(ray, out hit, 1000))
          {
            position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
          }
        }
        void moveToPosition()
        {
              //Game Object is moving
            if(Vector3.Distance(transform.position, position)>1)
            {
                Quaternion newRotation = Quaternion.LookRotation(position-transform.position, Vector3.forward);

                newRotation.x = 0f;
                newRotation.z = 0f;

          transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
          controller.SimpleMove(transform.forward * speed);

          animation.Play(run.name);
        }
        //Game Object is not moving
        else
        {
            animation.Play(idle.name);
        }
      }

    }
c# unity3d
1个回答
0
投票

[尝试在Unity内部创建脚本(右键单击内部资产文件夹),然后从当前脚本复制逻辑。给它起一个不同的名字。也尝试重新启动Unity和VS。

© www.soinside.com 2019 - 2024. All rights reserved.