Question by
JakeTeaman · Mar 29, 2020 at 05:27 PM ·
c#2d gameteleport
How to limit palyer player movement to circle
So i'm currently makeing puzzle game where main mechanic is to teleport player around but the challange comes from player limited ability to teleport. and here is problem i have already made simple script that teleports player to mouse position but, i dont really know how to limit this ability.
Purple is where Player can move, cursor is mouse cursor and the circle is where i want player to teleport. Here is my simple teleportation script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleportation : MonoBehaviour
{
public Transform player;
public Camera cam;
Vector2 mousePos;
private void Update()
{
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
if(Input.GetKeyDown(KeyCode.Mouse0))
{
player.position = mousePos;
}
}
}
Thx for help.
155407-obszar-roboczy-1.png
(49.3 kB)
Comment