【发布时间】:2015-12-06 02:07:49
【问题描述】:
我有一个附加到游戏对象的 Projectile 脚本。现在我想从附加到游戏对象 A 的脚本 A 访问 Projectile 脚本中的 LinearProjectile() 方法。这里我在脚本 A 中创建了一个 Projectile 类型的公共字段,并传入一个附加了 Projectile 脚本的游戏对象。
要访问我刚刚做的 LinearProjectile() 方法。
projectile.LinearProjectile(transform.position, transform.rotation, this.direction, this.shotPower);
//Here is my method defination..
public void LinearProjectile(Vector3 position, Quaternion rotation, Vector2 direction, float force)
{
Debug.Log("called");
this.direction = direction;
this.force = force;
this.projectileType = ProjectileType.Linear;
}
在这个方法中分配的所有字段值都处于默认状态,因为这个方法永远不会被调用。如何从其他 GameObject 脚本访问此方法。 我尝试了 GetComponent().method() 但即使我无法访问这里的错误是什么?我花了很多时间找出来但没有成功..帮帮我
【问题讨论】:
-
LinearProjectile()在哪里?在Projectile脚本中?如果是这样,你想在哪里访问LinearProjectile()? -
这是 Projectile Script 的一种方法,我想从 Script A 访问。