请问为什么在方法中使用访问修饰符会报错?
在学习过程中,偶然把原文定义到方法外的字段写到了方法中,结果似乎整个方法的性质都放生了改变程序代码:
using UnityEngine; public class Graph : MonoBehaviour { public Transform pointPrefab; public int resolution = 10; private void Awake() { private int a ;//这句原文为字段 Vector3 scale = Vector3.one / 5f; Vector3 position; //position.y = 0f; position.z = 0f; for (int i = 0; i < 10; i++) { Transform point = Instantiate(pointPrefab); //point.localPosition = Vector3.right * ((i + 0.5f) /5f -1f); position.x = (i + 0.5f) / 5f - 1f; position.y = position.x * position.x; point.localPosition = position; point.localScale = scale; } } }就比如position提示“不存在position”,请问其中的道理是什么?
[此贴子已经被作者于2019-8-29 11:45编辑过]