Hi guys,
I am completely new to Unity and would like some help.
I am trying to make a script / action in C# where if a button is clicked a text will appear for about 0.5 seconds within a certain area and then disappear.
Are you able to point me to the right direction or possibly give me a step by step guide on what to write? or a code with //comments above that i can follow and understand what is going on.
Thanks
EDITED Well try something this way:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class OnClick : MonoBehaviour {
public GameObject popUP; // prefab to instantiate
public Canvas canvas; // father canvas
private Vector2 position = new Vector2(0,0);
void Start()
{
position.x = Random.Range(-10f, 10f);
position.y = Random.Range(-10f, 10f);
}
public void PopUP ()
{
GameObject inst = (GameObject) Instantiate(popup, position, Quaternion.identity);
inst.transform.SetParent(canvas.transform);
Destroy(inst, 1.0f);
}
}
Your button must have this script linked and activate the Popup function.