简体   繁体   English

从C#启用UnityScript

[英]Enable UnityScript from C#

I am trying to figure out how I can enable and disable a UnityScript (Plates_p) which is attached to my main camera from another C# script. 我试图弄清楚如何启用和禁用从另一个C#脚本附加到我的主摄像机的UnityScript(Plates_p)。 I have tried this: 我已经试过了:

Camera.main.GetComponent<Plates_p>().enabled = false;

This throws this error: The type or namespace name `Plates_p' could not be found. 这将引发此错误:找不到类型或名称空间名称“ Plates_p”。 Are you missing a using directive or an assembly reference? 您是否缺少using指令或程序集引用?

I have also tried this: 我也尝试过这个:

Plates_p myscript;

This throws the same error? 这引发同样的错误? How do I solve this? 我该如何解决?

Any help is appreciated :-) 任何帮助表示赞赏:-)

It's not that easy and it's recommended (or rather just much easier :) ) to only use one language. 并不是那么容易,并且建议(或者更简单的是:))只使用一种语言。 You can't access the other script directly but you can use sendMessage. 您不能直接访问其他脚本,但可以使用sendMessage。 With that you could create a trigger method that switches the state of your Plates_p in order to do something or don't. 这样,您可以创建一个触发方法来切换Plates_p的状态以执行某项操作或不执行某项操作。 I don't think you can reanable it through the use of sendMessage, but I'm not sure though. 我认为您无法通过使用sendMessage重新启用它,但是我不确定。

Here you can read about accessing scripts in different languages: http://forum.unity3d.com/threads/23274-Mixing-C-and-Javascript-how http://docs.unity3d.com/Documentation/ScriptReference/Component.SendMessage.html 在这里,您可以了解有关使用不同语言访问脚本的信息: http : //forum.unity3d.com/threads/23274-Mixing-C-and-Javascript-如何 http://docs.unity3d.com/Documentation/ScriptReference/Component。 SendMessage.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM