Ejemplo n.º 1
0
 public override void UseAgainst(BaseObject source, BaseObject target)
 {
     if ((source.Transform.position - target.Transform.position).magnitude >= _resource.MinRange)
     {
         OnTargetHitHandler?.Invoke(target);
     }
 }
Ejemplo n.º 2
0
            /// <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);
 }
Ejemplo n.º 4
0
 public override void UseAgainst(BaseObject target)
 {
     OnTargetHitHandler.Invoke(target);
 }
Ejemplo n.º 5
0
 public override bool Use(BaseObject source)
 {
     OnTargetHitHandler?.Invoke(source);
     return(true);
 }