Пример #1
0
        void CheckRaycast(Vector3 startPos)
        {
            //		Debug.Log ("t1:" + t1 + ",t2:" + t2 + ", lr pos:" + lr.GetPosition(0));
            lr.SetPositions(new Vector3[] { Vector3.fwd *t1 *speed, Vector3.fwd *t2 *speed });
//			Debug.Log ("startpos:" + startPos);
            //		Vector3 dir = lr.GetPosition (0) - lr.GetPosition (1);
            float   dist   = Vector3.Magnitude(lr.GetPosition(0) - lr.GetPosition(1)) * 3f;            // times 3 beacuse unity frame updates are too slow and might "miss" the target between raycasts otherwise
            Vector3 offset = -Camera.main.transform.forward * 0.15f;

            foreach (RaycastHit hit in Physics.RaycastAll(new Ray(startPos + offset, Camera.main.transform.forward), dist))
            {
                //			FindObjectOfType<DebugText>().GetComponent<UnityEngine.UI.Text>().text = "hit:"+hit.collider;
//				CLogger.Log("hit:"+hit.collider);
                DamageReceiver dr = hit.collider.GetComponent <DamageReceiver> ();
                if (dr)
                {
                    if (dr.DirectionValid(Camera.main.transform.forward) || dr.directional == false)
                    {
                        dr.TakeDamage(dg.damageAmount);
                        Destroy(dg);

                        GameObject exp = (GameObject)Instantiate(explosion, hit.point, Quaternion.identity);
                        dying = true;
                    }
                }
            }
        }
Пример #2
0
        void Update()
        {
            RaycastHit hit;

            if (Physics.Raycast(new Ray(rp.lastPosition, rp.nowPosition - rp.lastPosition), out hit, (rp.lastPosition - rp.nowPosition).magnitude * 4f))
            {
                DamageReceiver dr = hit.collider.GetComponent <DamageReceiver> ();
                if (dr)
                {
                    if (!dr.directional || dr.DirectionValid(rp.lastPosition - rp.nowPosition))
                    {
                        dr.TakeDamage(damageAmount);
                        dr.DamageFx(this);
                        Destroy(this);
                    }
                }
            }
        }