Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

RayCasting + Animation Problem

$
0
0
So I have my raycasting script for shooting a "rifle" at a Raptor but it only seems to work when he is in his walking animation and not any of the other animations. I am using an Animator Controller for the raptor. Here is my raycast code. using UnityEngine; using System.Collections; public class RifleWeapon : MonoBehaviour { [SerializeField] int _damageDealt = 10; void Start () { Screen.lockCursor = true; } void Update () { if (Input.GetKey (KeyCode.Escape)) { Screen.lockCursor = false; } if (Input.GetButtonDown ("Fire1")) { Screen.lockCursor = true; Ray mouseRay = Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0)); RaycastHit hitInfo; if (Physics.Raycast (mouseRay, out hitInfo)) { Debug.Log(hitInfo.transform.name); Health enemyHealth = hitInfo.transform.GetComponent (); if (enemyHealth != null) { enemyHealth.Damage (_damageDealt); } } } } } And here is my raptor animation code. void OnTriggerStay (Collider other) { if (other.tag != "Player"&& _controller.isGrounded==false) { //Debug.Log ("we're NOT colliding with player!"); RaptorAnimator.SetBool ("RunDistance", false); _moveSpeed = 5; } else if (other.tag == "Player"&& _controller.isGrounded==false){ //Debug.Log ("we ARE colliding with player!"); RaptorAnimator.SetBool ("RunDistance", true); _moveSpeed = 25; } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>