Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to call a method from another script in my script using Invoke(),but unable to run it.How can i achieve this ?

Following is my code -

void Start () {

    int randNum;
    randNum = Random.Range(0,2);

    Debug.Log("random number == " + randNum);

    if(randNum == 0)
        Invoke("PositionScript.instance.MAttack",5f);

    if(randNum == 1)
        Invoke("PositionScript.instance.SAttack",5f);

}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The first parameter in Invoke takes only the name of the method you wish to call.

Assuming PositionScript.instance is set to a MonoBehaviour component of some sort:

PositionScript.instance.Invoke("MAttack",5f);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.