You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity 2D报错CS1061:Quaternion未包含eularAngles定义问题求助

开发目标

实现弹球游戏中按下A键时控制挡板旋转的功能。

报错信息

CS1061: Quaternion does not contain a definition for eularAngles and no accessible extension method eularAngles accepting a first argument of type Quaternion could be found (are you missing a using directive or an assembly reference?)

问题原因

编译失败由两个错误导致,与Quaternion归一化、类声明缺失无关:

  • 属性名拼写错误:欧拉角对应属性的正确写法为eulerAngles,原代码误将euler拼写为eular(第二个e错写为a)
  • 属性调用路径错误:eulerAngles是Transform类的直接成员,Quaternion类型本身未定义该属性,无需通过myTransform.rotation(Quaternion类型实例)访问
修正后代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class paddleLeft : MonoBehaviour{

    private Transform myTransform;

    void Start() {
        myTransform = gameObject.transform;
    }

    void Update() {
        if (Input.GetKey(KeyCode.A)) {
            var ourRotation = myTransform.eulerAngles;
            var newRotation = new Vector3(ourRotation.x, ourRotation.y, ourRotation.z + (5 * Time.deltaTime));
            myTransform.rotation = Quaternion.Euler(newRotation);
        }
    }
}

内容的提问来源于stack exchange,提问作者NatusPotatus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 20:06:28