两个脚本相互调用

设置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();

posted @ 2013-04-25 09:48  六界剑仙  阅读(190)  评论(0)    收藏  举报