GetTileIdAtPosition() public method

Gets the tile at position. This can be used to obtain tile data, etc -1 = no data or empty tile
public GetTileIdAtPosition ( Vector3 position, int layer ) : int
position Vector3
layer int
return int
コード例 #1
0
    private void FollowPath()
    {
        Vector3 target = patrolPath[pathIndex];

        //Utility.LogChangedValue("ReachedWaypoint", ReachedWaypoint (target));

        velocity = moveController.velocity;

        velocity.x    = target.x - transform.position.x;
        velocity.x    = Mathf.Sign(velocity.x) * walkSpeed;
        walkDirection = (int)Mathf.Sign(velocity.x);

        if (ladderMap == null || ladderMap.GetTileIdAtPosition(transform.position, 0) == -1)
        {
            velocity += Physics.gravity * Time.deltaTime;
            if (velocity.y < Physics.gravity.y)
            {
                velocity.y = Physics.gravity.y;
            }
        }
        else
        {
            velocity.y = 0f;
        }

        moveController.Move(velocity * Time.deltaTime);

        if (ReachedWaypoint(target))
        {
            pathIndex = patrolPath.GetNextWaypointIndex(pathIndex);
            Sleep(1);
        }
    }
コード例 #2
0
ファイル: Gameplay.cs プロジェクト: schmoey/wonderboy
    void Update()
    {
        if (isGoal)
        {
            if (!isGoalWalkStarted)
            {
                isGoalWalkStarted = true;

                player.animator.Play("Walk");
                player.animator.ClipFps = 2f;

                player.sprite.scale = new Vector3(player.sprite.scale.x * -1f, player.sprite.scale.y, player.sprite.scale.z);
            }
        }

        // Attempt to get ground position
        if (player.isGrounded)
        {
            tempGroundPosition  = lastGroundPositionY;
            lastGroundPositionY = player.transform.position.y;
        }

        if (!isFairyPause && player.isAlive && isGameReady)
        {
            // Falling death
            if (playerTransform.position.y < cameraTransform.position.y - camera.ScreenExtents.height / 2f)
            {
                player.Die(false, true);
            }

            if (player.isAlive)
            {
                UpdateScore();

                healthTimer -= Time.deltaTime;

                if (healthTimer < 0)
                {
                    healthTimer = healthTimerAmount;

                    Damage(1);
                }

                // FAIRY INVINCIBILITY COUNTDOWN
                if (isFairy)
                {
                    fairyTimer += Time.deltaTime;

                    if (fairyTimer >= fairyTime)
                    {
                        Fairy.instance.transform.DOLocalMove(new Vector2(8f, 18f), 2.5f).SetEase(Ease.Linear).OnComplete(() => {
                            isFairy = false;
                            Destroy(Fairy.instance.gameObject);
                        });

//						Fairy.instance.FlyAway ();
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }

            RaycastHit2D hit = Physics2D.Raycast(playerTransform.position, Vector2.down, 200f, LayerMask.GetMask("Ground TM"));

            if (hit)
            {
                tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1));

                if (tileInfo != null)
                {
                    if (tileInfo.intVal == 1)
                    {
                        isSlope = true;

                        tilemap.GetTileAtPosition(hit.point, out tileX, out tileY);
                    }
                    else
                    {
                        isSlope = false;
                    }
                }
                else
                {
                    isSlope = false;
                }

                int tileId = tilemap.GetTileIdAtPosition(hit.point, 1);

                tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1));
            }
        }
    }
コード例 #3
0
    // Update is called once per frame
    public void UpdateMovement()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");
        float jump       = Input.GetAxis("Jump");

        //Always set horizontal velocity exactly to requested speed
        velocity.x = horizontal * speed;

        //Detach from ladders when
        if (jump > 0)
        {
            attachedToLadder = false;
        }

        //Check if we are currently next to a ladder
        if (ladderMap != null)
        {
            nextToLadder = (ladderMap.GetTileIdAtPosition(transform.position, 0) != -1);
        }
        else
        {
            nextToLadder = false;
        }

        //Attach to a ladder only if next to one and the player is requesting vertical movement
        if (vertical != 0 && nextToLadder)
        {
            attachedToLadder = true;
            velocity.y       = 0;
        }
        if (!nextToLadder)
        {
            attachedToLadder = false;
        }

        //If the player is attached to a ladder and moving, do so but only if that won't move them outside the ladder
        if (attachedToLadder)
        {
            velocity.y = vertical * speed;
            //If moving in this direction would take us away from a ladder, cancel it
            if (ladderMap.GetTileIdAtPosition(transform.position + velocity * Time.deltaTime, 0) == -1)
            {
                velocity.y = 0;
            }
        }

        //Start a jump only when a jump has been pressed initially
        if (jump > 0 && !jumped)
        {
            if (moveController.isGrounded || attachedToLadder || onPlatform)
            {
                velocity += Vector3.up * jumpStrength;
                if (jumpSound != null)
                {
                    AudioSource.PlayClipAtPoint(jumpSound, transform.position);
                }
            }
            jumped = true;
        }
        else if (jump <= 0)
        {
            jumped = false;
        }

        //Apply gravity only if not attached to a ladder
        if (!attachedToLadder && !onPlatform)
        {
            velocity += Physics.gravity * Time.deltaTime * gravityFactor;
            if (velocity.y < Physics.gravity.y)
            {
                velocity.y = Physics.gravity.y;
            }
        }

        PerformMove();
    }