hi
i need help
i have to make a button that(3d model) when i press on it it will start another objects animation
what i want to make
i press a button and a object starts a animation and when the animation is done and i CAN press it again another animation begins
example:
i press a button and a door moves to the side so i can enter the room if i then press the button again when the animation IS done the door moves with another animation back where it started
The simplest (and less efficient way to do it) would be: Assign a boolean that keeps track of your animation(s). Raycast on mouse-up to get the button press and depending on whether said boolean is true/false, play animation one or animation two.
Hi here is a simple script to make an object act like a button with a OnClick event. Just attach this script to a 3d object you would like to make a button. Cheers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class WebsiteButton : MonoBehaviour {
public GameObject definedButton;
public UnityEvent OnClick = new UnityEvent();
// Use this for initialization
void Start () {
definedButton = this.gameObject;
}
// Update is called once per frame
void Update () {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit Hit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out Hit) && Hit.collider.gameObject == gameObject)
{
Debug.Log("Button Clicked");
OnClick.Invoke();
}
}
}
}