using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cshaper : MonoBehaviour {
private void Start()
{
Vector3 v1 = new Vector3();
//v1.x = 1;
//v1.y = 1;
//v1.z = 1;
v1.SetX(1);
v1.SetY(1);
v1.SetZ(1);
Debug.Log(v1.Length());
}
}
class Vector3
{
//编程规范上 习惯把所有的字段 设置为Private
private float x, y, z;
//为字段提供set方法,来设置字段的值
public void SetX(float x)
{
//如果我们直接在方法内部访问同名的变量的时候,优先访问最近(形参)
//我们可以通过this.表示访问的是类的字段或着方法
this.x = x;
}
public void SetY(float y)
{
this.y = y;
}
public void SetZ(float z)
{
this.z = z;
}
public float Length()
{
return (float)Mathf.Sqrt(x * x + y * y + z * z);
}
}