Advertisement
guinunez

Jugador.cs

Jul 31st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Jugador : MonoBehaviour {
  6.  
  7.     public float miVelocidad;
  8.     public float xMin, xMax, yMin, yMax;
  9.     public GameObject disparo;
  10.     public Transform spawner;
  11.     public float tiempoRepeticion;
  12.     private float siguienteTiro;
  13.  
  14.     void FixedUpdate() {
  15.         float moverHorizontal = Input.GetAxis("Horizontal");
  16.         float moverVertical = Input.GetAxis("Vertical");
  17.        
  18.         Vector3 movimiento = new Vector3(moverHorizontal, moverVertical, 0.0f);
  19.  
  20.         GetComponent<Rigidbody2D>().velocity = movimiento * miVelocidad;
  21.  
  22.         GetComponent<Rigidbody2D>().position = new Vector3(
  23.             Mathf.Clamp(GetComponent<Rigidbody2D>().position.x, xMin, xMax),
  24.             Mathf.Clamp(GetComponent<Rigidbody2D>().position.y, yMin, yMax),
  25.             0.0f);
  26.  
  27.     }
  28.  
  29.     void Update() {
  30.         if (Input.GetButton("Fire1") && Time.time > siguienteTiro) {
  31.             siguienteTiro = Time.time + tiempoRepeticion;
  32.             Instantiate(disparo, spawner.position, spawner.rotation);
  33.         }
  34.        
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement