Hi all,
After setting up things today and fiddling with code, I’m at a loss atm.
What I’ve done is set up all animation clips from my FBX, and in the animator window set up the transitions, parameters and conditions.
So:
- default base animation > Anim01 (condition: Anim01Run)
- default base animation > Anim02(condition: Anim02Run)
- default base animation > Anim03(condition: Anim03Run)
- Anim04 (endposition Anim01) > default base animation (condition: Anim04Run)
- Anim05 (endposition Anim02) > default base animation(condition: Anim05Run)
- Anim06 (endposition Anim03) > default base animation(condition: Anim06Run)
Every transition has the boolean parameter set to true for the condition. First three transitions have the ‘Has Exit Time’ turned off.
Only three objects can be clickable, and have a box collider for the trigger.
The Raycast code for the boxes works, and gives me a proper result in the log.
code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchCamAnims : MonoBehaviour
{
private Animator animatorvar;
//init
void Start()
{
animatorvar = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
// Define mouse pointer position on click in scene & object collider
if (Input.GetMouseButtonDown(0)) //0 refers to LMB
{
Ray mouseray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit rayhit;
if (Physics.Raycast(mouseray, out rayhit, 100.0f))
{
//select collider & activate animation
if (rayhit.transform.name == "cube1")
{
rayhit collider// the code here to play ("condition parameter for transition clips", true/false?)
Debug.Log("Clicked on mesh cube 1!");
}
if (rayhit.transform.name == "cube7")
{
Debug.Log("Clicked on mesh cube 7!");
}
if (rayhit.transform.name == "cube13")
{
Debug.Log("Clicked on mesh cube 13!"); // Play selected Animation Clip
}
}
}
}
}
What I cant get to work, is the code for the raycast & trigger for the animation clip.
Also, the idea is to be able to click on the object(s) one time to run Anim01, than again to run Anim02 etc.
I’ve been looking at the docs and some YT videos today, and tried all variations on animation and such, but I might running in circles atm…
cheers for any tips, links or tricks.
rob