protected override void ChangeAnimation(AnimalAnimation newAnimation)
    {
        if (currentAnimation != newAnimation)
        {
            currentAnimation = newAnimation;
            animator.SetBool("Eat", false);
            animator.SetBool("Run", false);
            animator.SetBool("Walk", false);

            switch (currentAnimation)
            {
            case AnimalAnimation.DIE:
                animator.SetBool("Die", true);
                audioSource.PlayOneShot(audioSource.clip);
                break;

            case AnimalAnimation.EAT:
                animator.SetBool("Eat", true);
                break;

            case AnimalAnimation.RUN:
                animator.SetBool("Run", true);
                break;

            case AnimalAnimation.WALK:
                animator.SetBool("Walk", true);
                break;

            default:
                break;
            }
        }
    }
Пример #2
0
    void animal()
    {
        string code = "while(1<3){walk 10 left 90;}";
        //Data.currentCode = code;
        GameObject      animal = GameObject.Instantiate(Data.files[0].file);
        AnimalAnimation _aa    = animal.AddComponent <AnimalAnimation>();
        AnimalStats     __as   = animal.AddComponent <AnimalStats>();

        __as.setType(0);
    }
Пример #3
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);
        }
    }