用户自建class中的访问方法transform.Rotate?

Accessing method transform.Rotate in user-built class?

我正在通过 Terry Norton "Learning C# by Developing Games with Unity #D Beginner's Guide" 学习 C# 和 Unity3D,但我被错误阻止了。

我在通过用户构建的 class 变量访问方法 transform.Rotate 时遇到问题。

下面是我得到的错误。

Assets/Code/States/SetupState.cs(26,76): error CS1061: Type PlayerControl' does not contain a definition fortransfrom' and no extension method transfrom' of typePlayerControl' could be found (are you missing a using directive or an assembly reference?)

SetupState.cs,试图访问的状态transform.Rotate 通过 PlayerControl 类型变量控制器.

using UnityEngine;
using Assets.Code.Interfaces;
using System.Collections;

namespace Assets.Code.States
{
    public class SetupState : IStateBase
    {
        private StateManager manager;
        private GameObject player;
        private PlayerControl controller;

        public SetupState (StateManager managerRef)
        {
            manager = managerRef;
            if(Application.loadedLevelName != "Scene0")
                Application.LoadLevel("Scene0");

            player = GameObject.Find ("Player");
            controller = player.GetComponent<PlayerControl> ();
        }

        public void StateUpdate ()
        {
            if (!Input.GetButton ("Jump"))
                                controller.transfrom.Rotate (0, controller.setupSpinSpeed * Time.deltaTime);
            //above tries to access transform.Rotate via controller
        }

        public void ShowIt ()
        {
            GUI.Box (new Rect (10, 10, 100, 180), "Player Color");

            if (GUI.Button (new Rect (20, 40, 80, 200), "Red"))
                                controller.PickedColor (controller.red);

            if (GUI.Button (new Rect (20, 70, 80, 200), "Blue"))
                controller.PickedColor (controller.blue);

            if (GUI.Button (new Rect (20, 100, 80, 200), "Green"))
                controller.PickedColor (controller.green);

            if (GUI.Button (new Rect (20, 130, 80, 200), "Yellow"))
                controller.PickedColor (controller.yellow);

            if (GUI.Button (new Rect (20, 160, 80, 200), "White"))
                controller.PickedColor (controller.white);

            GUI.Label (new Rect (Screen.width / 2 - 95, Screen.height - 100, 190, 30),
                       "Hold Spacebar to pause rotation");

            if (GUI.Button (new Rect (Screen.width / 2 - 100, Screen.height - 50, 200, 40),
                            "Click Here or Press 'P' to Play") || Input.GetKeyUp (KeyCode.P))
                                manager.SwitchState (new PlayStateScene1_1 (manager));
        }
    }
}    

PlayerControl.cs, class 定义为 class PlayerControl 显然。

using UnityEngine;
using System.Collections;

public class PlayerControl : MonoBehaviour {
    public float setupSpinSpeed = 50.0f;

    public Color red = Color.red;
    public Color blue = Color.blue;
    public Color green = Color.green;
    public Color yellow = Color.yellow;
    public Color white = Color.white;

    void Start () {
    }

    void Update () {

    }

    public void PickedColor(Color playerColor){
        renderer.material.color = playerColor;
        }
}

这本书提到 link 使用 3D 游戏对象 编写 脚本 PlayerControl.cs 是唯一的我需要做的事情来访问 方法 transform.Rotate 我做了 link PlayerControl.cs游戏对象"Player"在一起。 http://i.imgur.com/0oH9hYs.png //好像还不能上传图片

我的母语不是英语,这本书是韩语翻译的,所以有些术语可能使用不当,请原谅。这个问题是一个愚蠢的菜鸟问题,但请成为一个乐于助人的好人,谢谢。

您的 PlayerControl 脚本已链接到 Player GameObject。因此,您可以通过以下方式访问 Player GameObject 的变换 属性:

controller.gameObject.transform.Rotate

查看 MonoBehaviour 文档 gameObject 属性

困扰我的愚蠢问题的答案是正确的拼写转换。

抱歉打扰各位看书了,谢谢。