用Debug.Log()可以在unity的控制台中输出文字。
this.gameObject指代代码所在的物体。
而transform、position则是指代unity中的位置。
pos.ToString("F3")是保留三位小数。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleLogic : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("--开始测试--");
GameObject obj = this.gameObject;
string name=obj.name;
Debug.Log("物体的名字为:" + name);
Transform tr=obj.transform;
Vector3 pos = tr.position;
Debug.Log("物体的位置:"+pos.ToString("F3"));
}
// Update is called once per frame
void Update()
{
}
}