![](/img/trans.png)
[英]How to fix C# error “The type or namespace name '[x]' could not be found (are you missing a using directive or an assembly reference?)”
[英]The type or namespace name 'ScriptName' could not be found (are you missing a using directive or an assembly reference?) fix unity c#
我正在尝试引用附加到对象父级的另一个脚本。 这是我尝试使用的代码
ScriptName sn = transform.parent.gameObject.GetComponent<Initializer>();
这是我试图引用的脚本的开头
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Initializer : MonoBehaviour
我不太确定劫持是什么。 我试过谷歌搜索,但似乎没有任何帮助。 我不知何故失踪的明显修复是什么? 提前致谢
您正在尝试将 Initializer 对象存储在“ScriptName”中。 你可能想要这个:
Initializer initializer = transform.parent.GetComponent<Initializer>();
请注意,您无需获取父级的 GameObject 即可访问 GetComponent() 函数。
您还可以使用GetComponentInParent()获取任何父组件中的组件。
Initializer initializer = GetComponentInParent<Initializer>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.