button function on unity5
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public Vector2 jumpForce = new Vector2(0, 300);
public GameObject Egg;
public Transform eggpoint;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp("space") || Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
}
if(Input.GetKeyDown(KeyCode.Return))
{
Instantiate(Egg, eggpoint.position, eggpoint.rotation);
}
}
}
so as you guys can see in the separate box how i am instantiating my egg droping code.and i am achieving this by pressing the return or enter button on the keyboard ,what i want to ask is how can i use a button to do it rather than the enter .so i have placed a ui button on my game screen but as i am absolute beginner i cant figure out how to connect the button and the function please guide me to the right tutorial.
Answer by UsmanAbbasi · Jun 07, 2016 at 06:14 PM
This is what you need: https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-button
You also should watch tutorials on Unity UI:
https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui?playlist=17111
Your answer
![](https://koobas.hobune.stream/wayback/20220612082444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to make a gaze work with a button? 0 Answers
Someone please help me with combination lock 0 Answers
How to catch events from scripted buttons 1 Answer
Adding buttons as components not working 0 Answers
Button calls itself numerous times 0 Answers