简体   繁体   English

如何在 Unity 中更改来自不同脚本的播放器组件?

[英]How Can I Change Player Components From Different Script In Unity?

I want to change RigidBody2D > Simulated to false from another game object scripts.我想从另一个游戏 object 脚本中将 RigidBody2D > Simulated 更改为 false。 Is it possible?可能吗?

Yes, it is possible.是的,有可能。 Try looking into GameObject.尝试查看 GameObject。 GetComponent . 获取组件 It will allow you to get any component from a given gameobject.它将允许您从给定的游戏对象中获取任何组件。

public Gameobject otherobject; //you can set this in code or inspector
private Rigidbody2D rb;
void Start(){
    rb = otherobject.GetComponent<Rigidbody2D>();
    rb.simulated= false;
}

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

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