コード例 #1
0
    private void FixedUpdate()
    {
        if (isDead)
        {
            return;
        }

        // Chase/Fighting Code
        if (inCombat)
        {
            Vector3 moveVector = player.transform.position - transform.position;
            moveVector.Normalize();
            moveVector *= runSpeed / 50;
            var angle = Mathf.Atan2(moveVector.y, moveVector.x) * Mathf.Rad2Deg;

            if (prop != null)
            {
                prop.useDirection = moveVector;
            }

            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            if (shouldChase)
            {
                if (prop)
                {
                    prop.StopPropUse();
                }
                transform.position += moveVector;
            }
            else if (prop && prop.canUse)
            {
                prop.UseProp();
            }
        }
        // Following waypoints code
        else if (waypoints.Length > 0 && waypointIndex < waypoints.Length)
        {
            // Move the player towards the next waypoint
            Vector3 moveVector = waypoints[waypointIndex] - transform.position;
            moveVector.Normalize();
            moveVector         *= walkSpeed / 50;
            transform.position += moveVector;

            var angle = Mathf.Atan2(moveVector.y, moveVector.x) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            // If close to the waypoint, move onto the next one
            if (Vector3.Distance(waypoints[waypointIndex], transform.position) < 0.5f)
            {
                if (backTracking)
                {
                    waypointIndex--;
                    if (waypointIndex == -1)
                    {
                        waypointIndex = 0;
                        backTracking  = false;
                    }
                }
                else
                {
                    waypointIndex++;
                    if (waypointIndex == waypoints.Length)
                    {
                        switch (loopPath)
                        {
                        case EndOfPathBehaviour.LOOP:
                        {
                            waypointIndex = 0;
                            break;
                        }

                        case EndOfPathBehaviour.BACKTRACK:
                        {
                            backTracking  = true;
                            waypointIndex = waypoints.Length - 1;
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (adjacentProp != null)
        {
            adjacentProp.useDirection = GetComponent <ThePlayer>().getCurrentDirection();


            if (!pickedUpProp)
            {
                if (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("NES BUTTON A"))
                {
                    adjacentProp.PickUpProp(transform);
                    pickedUpProp = true;
                }
            }
            else
            {
                if (!usingProp && adjacentProp.canUse && (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("NES BUTTON A")))
                {
                    Debug.Log("down");
                    adjacentProp.UseProp();
                    usingProp = true;
                }
                else if (usingProp && (Input.GetKeyUp(KeyCode.Space) || Input.GetButtonUp("NES BUTTON A")))
                {
                    Debug.Log("up");
                    adjacentProp.StopPropUse();
                    usingProp = false;
                }
            }



            //adjacentProp.useDirection = direction;
            ////Debug.Log(adjacentProp.useDirection);

            //if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetButtonDown("NES BUTTON B"))
            //{
            //    if (!pickedUpProp)
            //    {
            //        adjacentProp.PickUpProp(transform);
            //        pickedUpProp = true;
            //    }
            //    else
            //    {
            //        Debug.Log("Throw Prop");
            //        pickedUpProp = false;
            //        //If player is not moving then throw is set to a default direction
            //        adjacentProp.ThrowProp( throwSpeed);

            //    }
            //}
            //else if (HasProp())
            //{
            //    if (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("NES BUTTON A"))
            //    {
            //        adjacentProp.UseProp();
            //    }
            //    else if (Input.GetKeyUp(KeyCode.Space) || Input.GetButtonUp("NES BUTTON A"))
            //    {
            //        adjacentProp.StopPropUse();
            //    }
        }
    }