public override void UseAgainst(BaseObject source, BaseObject target) { if ((source.Transform.position - target.Transform.position).magnitude >= _resource.MinRange) { OnTargetHitHandler?.Invoke(target); } }
/// <summary> /// Returns succesful use /// </summary> /// <param name="actor"></param> /// <param name="action"></param> /// <returns></returns> // We dont care whihc type of actor public override bool Use(BaseObject source) { // TODO: for now we use closest, other options maybe? // TODO min range? Collider[] colliders = Physics.OverlapSphere(source.Transform.position, _resource.MaxRange); // TODO use priority instead? e.g healer should still be able to heal each other altough not in priority float dist = Mathf.Infinity; float cmp = -1f; BaseObject candidate = null; foreach (Collider collider in colliders) { var tg = collider.GetComponentInParent <BaseObject>(); if (tg == null) { continue; } if (tg.gameObject == source.gameObject) { continue; } cmp = Vector3.Distance(tg.Transform.position, tg.Transform.position); if (dist > cmp) { dist = cmp; candidate = tg; } } if (candidate == null) { return(false); } OnTargetHitHandler?.Invoke(candidate); return(true); }
public void OnHit(BaseObject target) { _direction = (target.Transform.position - _source.Transform.position).normalized; OnTargetHitHandler?.Invoke(target); }
public override void UseAgainst(BaseObject target) { OnTargetHitHandler.Invoke(target); }
public override bool Use(BaseObject source) { OnTargetHitHandler?.Invoke(source); return(true); }