Animation on raycast enter trigger ?
Hello! I am new to coding and scripting, but I have a problem with a script and I cant seem to solve it:
I have a riddle in my game, where the player has to rotate big wheels with signs on em. If he gets the right combination, an animation should play. I solved it this way:
A ray shots from the left side through the wheels. The wheels have colliders, except on the right sign. This means, if all the wheels have the right position, the ray can shoot through, on the other side and there is a collider. As soon the ray hits the collider, an animation should play (which is on a different gameobject), but I am not able to get the script to work!
Heres what I got so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class raycastforward : MonoBehaviour
{
// Update is called once per frame
void Update()
{
RaycastHit hit;
float theDistance;
Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
Debug.DrawRay(transform.position, forward, Color.green);
if (Physics.Raycast(transform.position, (forward), out hit))
{
theDistance = hit.distance;
print(theDistance + " " + hit.collider.gameObject.name);
}
if (other.CompareTag("RaycastTarget"))
{
GetComponent<Animator>().SetTrigger("Move_Rack");
}
}
}
}
I looked on some examples on the internet bu I always get some errors.
Your answer
Follow this Question
Related Questions
How too climb a ladder with the FPS Controller correctly 0 Answers
OVR Walking Animation trigger. 0 Answers
How to reduce the scale of the x and z axis ,How to reduce the x and z scale in a time lapse 0 Answers
Always wondered how to sync animations with attack effects 0 Answers
Unity animator always running only one animation...... 1 Answer