Unity Method Attributes

using UnityEngine;
using System.Collections;

public class MyContextMenu : MonoBehaviour {
    public int lives = 10;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    [ContextMenu("Add a life")]
    void AddMethod() {
        Debug.Log("Add Option of the Context Menu");
        lives++;
    }

    [ContextMenu("Reset life")]
    void ResetMethod() {
        Debug.Log("Reset life Option of the Context Menu");
        lives= 0;
    }

    [ContextMenu("Remove life")]
    void RemoveMethod() {
        Debug.Log("Remove life Option of the Context Menu");
        lives --;
    }

    [ContextMenu("Change Color")]
    void CallMethodPeter() {
        Peter();
    }

    [ExecuteInEditMode]
    public void Peter() {
         
        if (Application.isPlaying) {
            GameObject.Find("Cube").GetComponent().sharedMaterial.color = Color.red;
            StartCoroutine("ttime");

        }
        else {
              print("Must be in playmode");
        }

    }

    IEnumerator ttime() {
        yield return new WaitForSeconds(2);
        GameObject.Find("Cube").GetComponent().sharedMaterial.color = Color.white;
        StopCoroutine("ttime");
    }
}


Add a Comment

Your email address will not be published. Required fields are marked *

6 + 5 =