Example #1
0
        private Transform rightPosition;                      //右边枝子的位置


        /// <summary>
        /// 唤醒的时候
        /// </summary>
        private void Awake()
        {
            CircleCollider2D[] circleCollider2Ds = gameObject.GetComponents <CircleCollider2D>();

            foreach (CircleCollider2D myCollider2D in circleCollider2Ds)
            {
                if (!myCollider2D.isTrigger)
                {
                    radius = myCollider2D.radius;
                }
                else
                {
                    TriggerCollider = myCollider2D; //得到触发碰撞器
                }
            }

            path          = transform.parent.parent.Find("path").GetComponent <Path>();             //路径
            birdAnim      = transform.GetChild(0).GetComponent <BirdAnim>();                        //得到动画
            springJoint2D = GetComponent <SpringJoint2D>();                                         //得到弹性组件
            rigidBody2D   = GetComponent <Rigidbody2D>();                                           //得到这个小鸟的刚体组件

            leftPosition  = transform.parent.parent.Find("branch").Find("leftBranch").GetChild(0);  //左边的位置
            rightPosition = transform.parent.parent.Find("branch").Find("rightBranch").GetChild(0); //右边的位置

            leftLine  = leftPosition.GetComponent <LineRenderer>();
            rightLine = rightPosition.GetComponent <LineRenderer>();

            float xGridNum = Screen.width / (Screen.height / 10f); //水平网格数
        }
Example #2
0
    void shoot(Vector3 position, Vector3 direction, bool audioFlag)
    {
        //Camera cam = Camera.main;
        //Debug.Log("shoot");
        RaycastHit hit = new RaycastHit();
        Ray        ray = new Ray(position, direction);

        if (Physics.Raycast(ray, out hit))
        {
            Debug.Log("hit name:" + hit.collider.name);
            string          tag = hit.collider.tag;
            ShootingHandler sh  = hit.collider.gameObject.GetComponent <ShootingHandler>();
            if (sh != null)
            {
                //Debug.Log("shooting handler working.");
                sh.gotShot();
            }
            else if (tag == "animal" || tag == "bird")
            {
                placeBullet(hit.point);
                //animal handling
                AnimalAnimation animA = hit.collider.gameObject.GetComponent <AnimalAnimation>();

                if (animA)
                {
                    animA.gotShot();
                }
                //bird handling
                else
                {
                    BirdAnim animB = hit.collider.gameObject.GetComponent <BirdAnim>();

                    if (animB)
                    {
                        animB.gotShot();
                    }
                }
            }
            else if (tag == "run train")
            {
                if (distance(hit.point) < _trainTriggerDist)
                {
                    Data.triggerObj = hit.collider.gameObject;
                    runTrain(false);
                }
            }
            else if (tag == "train ride")
            {
                if (distance(hit.point) < _trainTriggerDist)
                {
                    Data.triggerObj = hit.collider.gameObject;
                    runTrain(true);
                }
            }
            else if (tag == "vehicle")
            {
                if (distance(hit.point) < _trainTriggerDist)
                {
                    Debug.Log("vehcle running.");
                    startDrive(hit);
                    //runTrain(true);
                }
            }
            else if (tag == "reflector")
            {
                Vector3 newDir = getReflection(direction, hit.collider.transform.forward);
                Debug.Log("reflector:" + hit.collider.name + "\tinbound:" + direction + "normal:" + hit.collider.transform.forward + "point:" + hit.point + "dir:" + newDir);;
                shoot(hit.point, newDir, false);
            }
            else
            {
                placeBullet(hit.point);
            }
        }
        if (audioFlag)
        {
            if (_src == null)
            {
                _src = gameObject.AddComponent <AudioSource>();
            }
            _src.PlayOneShot(sound);
        }
    }