Skip to content

Instantly share code, notes, and snippets.

@pmarinr
Created October 20, 2014 13:32
Show Gist options
  • Save pmarinr/18495765d147c7cfef30 to your computer and use it in GitHub Desktop.
Save pmarinr/18495765d147c7cfef30 to your computer and use it in GitHub Desktop.
3 modos de mover un objeto 2D
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