Quantcast
Viewing latest article 6
Browse Latest Browse All 48

Raycast/Melee Attack Help Please!

Okay so I'm making a melee weapon script that uses a raycast to get the distance from you to the enemy and when the enemy comes within distance and the player clicks, it does damage to the enemy. i'm just having trouble getting this to work.. any help would be appreciated! These are the errors: Error CS1502: The best overloaded method match for 'UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit)' has some invalid arguments (CS1502) (Assembly-CSharp) Error CS1620: Argument '3' must be passed with the 'out' keyword (CS1620) (Assembly-CSharp) using UnityEngine; using System.Collections; public class MeleeSystem : MonoBehaviour { int Damage = 50; float Distance; float MaxDistance = 2; Transform TheSystem; void Update (){ if (Input.GetButtonDown("Fire1")) { TheSystem.animation.Play("melee_attack"); RaycastHit hit; if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) { Distance = hit.distance; if (Distance < MaxDistance) hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver); } } } }

Viewing latest article 6
Browse Latest Browse All 48

Trending Articles



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