Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: ibzero on July 26, 2011, 12:39:23 PM

Title: Invoke Method instance of prefab
Post by: ibzero on July 26, 2011, 12:39:23 PM
Hi,
I'm trying to start a timer when a player enters an area and I have a script for the timer that is attached to a GUI Text object ( to display to the user) in a prefab. The prefab is called "Timer" and shows up in playmakers 'select game object' field however the scene instance of the prefab, named "TrackTimer" doesn't display the timer when run.

The first question is, why can't you select from the scene hierarchy rather than the concrete assets?

2nd: How do I get player maker to execute this script (from the unityforums):

Quote
/////////////////////////////////////////////
///Zapp's Uber fading timer script///////////
/////////////////////////////////////////////
///v3.141////////////////////////////////////
/////////////////////////////////////////////
///Brought to you by the letter Z..//////////
/////////////////////////////////////////////
///And a grant from the MyWallet Foundation//
/////////////////////////////////////////////
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class Timer : MonoBehaviour {

public int minutes;
public int seconds;
public int fraction;   

public float startTime;
float FadeStartTime;
float FadeTime;

public float playTime;
public float FadeSpeed;
   
public Color TimerColor = new Color(1,1,1,0);

   
bool go = false;
public bool fadeIn = false;
public bool fadeOut = false;   
   
   
   
    void Start ()
    {
        if( !guiText )
        {
            Debug.Log("This timer requires a GUIText component");
            enabled = false;
            return;
        }
       
        if(FadeSpeed == 0)
        {
            FadeSpeed = 1;
        }
        guiText.material.color = TimerColor;
      
    }
   
   
    void Update ()
    {
       
        //This is for testing, make sure to remove it after your done.
//        if(Input.GetMouseButtonDown(0))
//        {
//            if(!go)
//            {
//                StartTimer();
//            }
//            Fade();
//        }
               
        if(go)
        {
            playTime = Time.time - startTime;
            minutes = (int)(playTime/60f );
            seconds = (int)(playTime % 60f);
            fraction =  (int)((playTime *10) %10);
            guiText.text = string.Format("{0}\'{1}\"{2}", minutes, seconds, fraction);
        }
       
        if(fadeIn)
        {
            FadeIn();
        }
       
        if(fadeOut)
        {
            FadeOut();
        }
       
    }
   
    public void StartTimer()
    {
        Debug.Log("Timer Started");
      startTime = Time.time;
        go = true;
        FadeStartTime = Time.time;
        fadeIn = true;
    }
   
    public void StopTimer()
    {
        go = false;
    }
   
    public void Fade()
    {
        if( !fadeIn && !fadeOut )
        {
            FadeStartTime = Time.time;
            if(TimerColor.a == 1)
            {
                Debug.Log(TimerColor.a);
                fadeOut = true;
            }
            else
            {
                guiText.enabled = true;
                fadeIn = true;
            }
        }
        else
        {
       
            FadeStartTime = Time.time - ((1 - FadeTime) / FadeSpeed);
            fadeIn = !fadeIn;
            fadeOut = !fadeOut;
           
        }
    }
   
    void FadeIn()
    {
        FadeTime = (Time.time - FadeStartTime) * FadeSpeed;
        TimerColor.a = Mathf.SmoothStep(0, 1, FadeTime );
        guiText.material.color = TimerColor;
        if(TimerColor.a == 1)
        {
            fadeIn = false;
        }
    }
   
    void FadeOut()
    {
        FadeTime = (Time.time - FadeStartTime) * FadeSpeed;
        TimerColor.a = Mathf.SmoothStep(1, 0, FadeTime );
        guiText.material.color = TimerColor;
        if(TimerColor.a == 0)
        {
            fadeOut = false;
        }
    }
}