Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [System.Serializable]
- public class Boundary
- {
- public float xMin, xMax, zMin, zMax;
- }
- public class PlayerController : MonoBehaviour
- {
- public float speed;
- public float tilt;
- public Boundary boundary;
- public GameObject shot;
- public Transform shotSpawn;
- public float fireRate;
- private float nextFire;
- void Update()
- {
- //Input.GetButton
- //Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
- if (Input.GetButton("Fire1") && Time.time > nextFire) {
- nextFire = Time.time + fireRate;
- Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
- audio.Play();
- };
- /*
- if (Input.GetButton("Fire2") && Time.time > nextFire) {
- nextFire = Time.time + fireRate;
- Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
- audio.Play();
- }
- */
- }
- void FixedUpdate ()
- {
- float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertical = Input.GetAxis ("Vertical");
- Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
- rigidbody.velocity = movement * speed;
- // bang chuot
- Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- transform.position = Vector3.Lerp(transform.position, mousePos, Time.deltaTime * speed);
- // di chuyen bang cam bien
- /*
- Vector3 direction = Vector3.zero;
- direction.x = -Input.acceleration.z;
- direction.z = Input.acceleration.y;
- //* Time.deltaTime
- transform.Translate (direction * speed);
- */
- rigidbody.position = new Vector3
- (
- Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
- 0.0f,
- Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
- );
- rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment