示例#1
0
 // Update is called once per frame
 void Update()
 {
     fartTimer.Update();
     if (fartTimer.IsReady())
     {
         SpawnFart();
         fartTimer.Reset();
     }
 }
示例#2
0
    void CmdAttack(Vector3 mousePosition)
    {
        if (attackCooldown.IsReady())
        {
            attackCooldown.Reset();

            var isHit = false;

            //Use CapsuleCast to check whether it is hit
            RaycastHit[] hits;
            Vector3      p1        = transform.position;
            Vector3      direction = (mousePosition - p1).normalized;
            Vector3      p2        = p1 + direction * attackRange;

            // use spherecast instead of raycast so that the ray has a radius on it
            hits = Physics.SphereCastAll(p1, attackRadius, direction, attackRange, attackLayer);
            Debug.Log("hit count:" + hits.Length);
            Debug.DrawLine(p1, p2, Color.red, 1f);
            if (hits.Length > 0)
            {
                foreach (var hit in hits)
                {
                    var gameObject = hit.collider.gameObject;
                    var bob        = gameObject.GetComponent <Bob>();
                    if (bob != null)
                    {
                        Debug.Log("gardener: attack you!");
                        isHit = true;
                        bob.TakeDamage(attackDamage);
                        bob.RpcGetHurted(attackDamage);
                    }
                }
            }

            RpcAttack(isHit);
        }
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     fartCooldown.Reset();
 }