Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Intro_Scritping/Roguelike/Assets/Scripts/Player.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (34 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Player : MonoBehaviour { | |
//Declaration | |
public GameObject player; | |
public float xPos; | |
public float zPos; | |
public Vector3 playerPos; | |
public float distance; | |
public Ray ray; | |
public RaycastHit hit; | |
public Vector3 travel; | |
// Update is called once per frame | |
void Update () | |
{ | |
xPos = Input.mousePosition.x; | |
zPos = Input.mousePosition.z; | |
ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
if (Input.GetMouseButtonDown(1)) | |
{ | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
travel = new Vector3(hit.point.x, .5f, hit.point.z); | |
xPos = hit.point.x; | |
zPos = hit.point.z; | |
} | |
playerPos = new Vector3(xPos, 0.5f, zPos); | |
iTween.MoveTo(gameObject, playerPos, distance); | |
distance = Vector3.Distance(travel, transform.position); | |
} | |
playerPos = new Vector3(xPos, 0.5f, zPos); | |
// player.transform.position = playerPos; | |
} | |
} |