两个脚本相互调用
设置gameobject的tag值 这里设为Bullet.
在Script1.cs里有两个方法是
public void setBulletcnt(int iCnt)
{
iCurrentBulletCnt = iCnt;
}
public void jump()
{
Debug.Log("**************************************************************************************************");
}
在Script2.cs里调用
方法一:
GameObject.FindWithTag("fire").GetComponent<Bullet>().setBulletcnt(50);
GameObject.FindWithTag("fire").GetComponent<Bullet>().jump();
方法二:
public Script1 other;
other = (Bullet)GameObject.FindWithTag("fire").GetComponent("Bullet");
other.setBulletcnt(50);
other.jump();

浙公网安备 33010602011771号