Created
October 20, 2014 13:32
-
-
Save pmarinr/18495765d147c7cfef30 to your computer and use it in GitHub Desktop.
3 modos de mover un objeto 2D
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 moveScript : MonoBehaviour { | |
public int horizontalSpeed = 20; | |
public int verticalSpeed = 20; | |
private Vector3 mousePosition; | |
public float moveSpeed = 0.1f; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
//float h = horizontalSpeed * Input.GetAxis("Mouse X"); | |
//float v = verticalSpeed * Input.GetAxis("Mouse Y"); | |
float v = verticalSpeed * Input.GetAxis("Vertical"); | |
float h = horizontalSpeed * Input.GetAxis("Horizontal"); | |
Vector3 movement = new Vector3(h,v,0); | |
movement *= Time.deltaTime; | |
transform.Translate(movement); | |
if (Input.GetMouseButton(0)) { | |
mousePosition = Input.mousePosition; | |
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition); | |
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment