using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class simple01 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("hello,world");
GameObject obj = this.gameObject;
string name = obj.name;
Debug.Log("the name is:" + name);
Transform tr = obj.transform;
Vector3 ve1 = tr.position;
Vector3 ve2 = tr.localPosition;
Debug.Log(ve2 + " " + ve1.ToString("F3"));
}
// Update is called once per frame
void Update()
{
}
}
在Start()内编写程序,
在 SimpleLogic.cs 中,获取当前物体
1.this ,当前脚本组件
2 thisgameObject ,当前物体
this.gameObjedt.name ,当前物体的名字
3 this.gameObject.transform ,当前物体下的Transform组件为了简化书写,也可写作 this.transform ,效果相同
4.打印输出日志:Debug.Log();
5.精细度设置ve1.ToString("F3")
6.c#文件名必须和类名一致,若要修改类名,在vs中右键重命名