Exemplo n.º 1
0
    private void OnTriggerStay(Collider other)
    {
        string tag = other.gameObject.tag;

        if ((tag == "playerCopy" && blockPlayerAI) ||
            ((tag == "food" || tag == "poison" || tag == "foodAI") && blockFood))
        {
            ObjectBehaviour objectBehaviour = other.gameObject.GetComponent <ObjectBehaviour>();
            if (objectBehaviour != null)
            {
                Vector3 direction     = objectBehaviour.GetForwardDirection();
                bool    positiveLimit = (forceDirection == ForceDirection.Positive);
                bool    negativeLimit = (forceDirection == ForceDirection.Negative);
                float   theta         = Random.Range(0.0f, 2 * Mathf.PI);
                float   phi           = Random.Range(Mathf.PI / 3, Mathf.PI / 2);
                float   n1            = Mathf.Cos(theta) * Mathf.Cos(phi);
                float   n2            = Mathf.Sin(theta) * Mathf.Cos(phi);
                float   n3            = Mathf.Sin(phi);
                if (forceDirection == ForceDirection.Negative)
                {
                    n3 *= -1;
                }
                switch (verticalAxis)
                {
                case Axis.X:
                    if ((positiveLimit && direction.x < 0.0f) || (negativeLimit && direction.x > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n3, n1, n2));
                    }
                    break;

                case Axis.Y:
                    if ((positiveLimit && direction.y < 0.0f) || (negativeLimit && direction.y > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n2, n3, n1));
                    }
                    break;

                case Axis.Z:
                    if ((positiveLimit && direction.z < 0.0f) || (negativeLimit && direction.z > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n1, n2, n3));
                    }
                    break;
                }
            }
        }
        else if (tag == "player" && other.gameObject.GetComponent <Player>().photonView.isMine)
        {
            if (transform.parent.gameObject.GetComponent <MeshRenderer>() != null)
            {
                transform.parent.gameObject.GetComponent <MeshRenderer>().enabled = true;
            }
        }
    }
Exemplo n.º 2
0
    private void HandleWSAD()
    {
        //处理WSAD输入(改变角色的方向)
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical   = Input.GetAxis("Vertical");

        if (moveHorizontal > 0.0f)
        {
            if (moveVertical > 0.0f)
            {
                objectBehaviour.Move(ObjectBehaviour.MoveDirection.FrontRight);
            }
            else
            {
                objectBehaviour.Move(ObjectBehaviour.MoveDirection.Right);
            }
        }
        else if (moveHorizontal < 0.0f)
        {
            if (moveVertical > 0.0f)
            {
                objectBehaviour.Move(ObjectBehaviour.MoveDirection.FrontLeft);
            }
            else
            {
                objectBehaviour.Move(ObjectBehaviour.MoveDirection.Left);
            }
        }
        else if (moveVertical > 0.0f)
        {
            if (playerBehaviour.flyState == PlayerBehaviour.FlyState.Flying)
            {
                Vector3 towards = objectBehaviour.GetForwardDirection();
                playerBehaviour.MoveInSky(towards);
            }
            else if (playerBehaviour.enterSky && playerBehaviour.flyState == PlayerBehaviour.FlyState.WaitForFly)
            {
                playerBehaviour.MoveInSeaSurface();
            }
            else
            {
                objectBehaviour.Move(ObjectBehaviour.MoveDirection.Front);
            }
        }
        else
        {
            objectBehaviour.Move(ObjectBehaviour.MoveDirection.Stay);
        }
    }
Exemplo n.º 3
0
    protected IEnumerator CheckObstacle()
    {
        while (true)
        {
            Vector3 checkDirection = objectBehaviour.GetForwardDirection();
            Ray     checkRay       = new Ray(transform.position, checkDirection);
            float   checkDistance  = 5.0f;

            RaycastHit hit;
            if (Physics.Raycast(checkRay, out hit, checkDistance))
            {
                HandleCheckObstacle();
            }

            yield return(new WaitForSeconds(0.5f));
        }
    }