程序代码:
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// /// </summary> public class Fractal : MonoBehaviour { //网格 材质 public Mesh mesh; public Material material; //生成深度 上限 private int depth; public int maxDepth ; //子物体缩放 public float childScale; private void Start() { //给空物体 添加网格和材质组件,并指定样式 gameObject.AddComponent<MeshFilter>().mesh = mesh; gameObject.AddComponent<MeshRenderer>().material = material; //限制生成深度 if(depth < maxDepth) new GameObject("Fractal Child").AddComponent<Fractal>(). Initialize(this); } /// <summary> /// 在start()之前调用,对字段赋值 /// </summary> /// <param name="parent"></param> private void Initialize(Fractal parent) { mesh = parent.mesh; material = parent.material; maxDepth = parent.maxDepth; depth = parent.depth + 1; childScale = parent.childScale; this.transform.parent = parent.transform; transform.localScale = Vector3.one * childScale; //不懂 transform.localPosition = Vector3.forward * (0.5f + 0.5f * childScale); //transform.localPosition = Vector3.forward * 0.5f + Vector3.forward * (0.5f * childScale); Debug.Log(this.transform.localPosition); Debug.Log(this.transform.position); Debug.Log(depth); } }请帮我理解一下第47,虽然行为逻辑上理解(父物体一半宽+子物体一半宽)
但就是无法理解是怎么做到的(比如0.5 是怎么来的,为什么任意改变childScale不会影响结果)。
[此贴子已经被作者于2019-8-18 14:54编辑过]