//using System.Collections; //using System.Collections.Generic; using UnityEngine; public class WeaponController : MonoBehaviour { public bool haveGun = false; public GameObject bulletPrefab; public Transform weaponPosition; public GameObject bulletShooted; public float shootSpeed; public float bulletOffset = .5f; public GameObject Gun; public PlayerMovementController pmc; public CameraController cc; public Transform playerRotation; // Use this for initialization void Start () { } // Update is called once per frame void Update () { cc = Camera.main.GetComponent(); if (haveGun) { Gun.GetComponent().enabled = true; if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown("joystick button 0")) { Shoot(); } } else { Gun.GetComponent().enabled = false; } } void Shoot() { //transform.rotation = new Quaternion(0, 0, playerRotation.rotation.y, 0); this.gameObject.GetComponent().Play(); if (pmc.isLeft) { bulletShooted = Instantiate(bulletPrefab, new Vector2(weaponPosition.position.x - bulletOffset, weaponPosition.position.y), playerRotation.rotation); bulletShooted.GetComponent().velocity = transform.TransformDirection(Vector2.right * Time.deltaTime * shootSpeed * 100 * (1/Time.timeScale)); } else { bulletShooted = Instantiate(bulletPrefab, new Vector2(weaponPosition.position.x + bulletOffset, weaponPosition.position.y), playerRotation.rotation); bulletShooted.GetComponent().velocity = transform.TransformDirection(Vector2.right * Time.deltaTime * shootSpeed * 100 * (1 / Time.timeScale)); } cc.isShakcing = true; } }