一564 2023-01-15 10:07 采纳率: 100%
浏览 39
已结题

如何解决这个CS0246错误

当我将下面这段代码导入到unity时报错CS0246,The type or namespace name 'transform' could not be found (are you missing a using directive or an assembly reference?)是为什么,应该如何解决出,初学者


```c#
using System.Collections.Specialized;
using System.Transactions;
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Objectcontrol : Base {
    private Vector3 primitivePos;
    private Vector3 primitiveRot;
    private Vector3 tempPos;
    private bool canMove;

    public transform t;
    private float Distance;
    void Start(){
        Distance = 1;
        canMove = true;
        primitivePos = transform.position;
        primitiveRot = transform.eulerAngles;
        tempPos = Vector3.Zero;
    }

    
    void Update(){
        if (canMove)
            Movementto(t.position, Distance);
    }



    protected override void Movementto(Vector3 go, float dis)
    {
        if(Vector3.Distance(transform.position, go) > dis)
        {
            tempPos = go;
            tempPos.y = transform.position.y;
            transform.Lookat(tempPos);
            transform.translate(Vector3.forward * Time.deltaTime * 5);

        }
        else
        {
            if(dis > 0.1f)
            {
             
            }
            else
            {
               Goback();
            }

        }
        
    }
    
    private void Goback()
    {
        transform.position = primitivePos;
        transform.eulerAngles = primitiveRot;
        canMove = false;
    }
}


```

  • 写回答

1条回答 默认 最新

  • Halifax ‎ 2023-01-15 10:18
    关注

    望采纳。。。

    transform 需要把首字母改成大写:Transform

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月23日
  • 已采纳回答 1月15日
  • 创建了问题 1月15日

悬赏问题

  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?