12-01-2016, 10:28 PM
(Questo messaggio è stato modificato l'ultima volta il: 12-01-2016, 10:29 PM da alessiobb3b.)
Ah Ok Scusa :p
Codice:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Spar_Caspiterina : MonoBehaviour {
public Rigidbody Bullet;
public Rigidbody Boss , Rel_;
public Transform Boss_spawn;
public Transform Spawn;
private int CurrentCartridge = 8;
private int CurrentAmmo = 32;
private int MaxCartridge = 8;
private Animation Anima;
public string Fire , Rel , End_Fire;
public GameObject Bull;
public bool Ended;
public AudioClip Reload;
public Transform Aim_Pos , Normal_pos;
public float A , B;
public ParticleSystem Fires;
public GameObject Garand;
private Rigidbody BulletInstance;
private Rigidbody BossInstance;
private Rigidbody RelInstance;
void Start ()
{
Fires.Stop ();
}
// Update is called once per frame
void Update ()
{
//Aim ();
Fuoco();
Ricarica ();
}
void Aim()
{
if (Input.GetMouseButton (1)) {
Garand.transform.localPosition = Vector3.Lerp (transform.localPosition, Aim_Pos.position, 0.1f);
Garand.transform.localRotation = Quaternion.Slerp (transform.localRotation, Aim_Pos.rotation, 0.1f);
}
else
{
Garand.transform.localPosition = Vector3.Lerp (transform.localPosition, Normal_pos.position, 0.1f);
Garand.transform.localRotation = Quaternion.Slerp (transform.localRotation, Normal_pos.rotation, 0.1f);
}
}
void Fuoco()
{
if (Input.GetMouseButtonDown (0) && CurrentCartridge > 0 && Garand.GetComponent<Animation>().isPlaying==false)
{PlayerPrefs.SetInt("Fire" , 1);
Fires.Play();
CurrentCartridge --;
BulletInstance = Instantiate(Bullet, Spawn.position, Spawn.rotation) as Rigidbody;
BulletInstance.AddForce(Spawn.forward * 5000);
print(BulletInstance.position.ToString());
BossInstance = Instantiate(Boss, Boss_spawn.position, Boss_spawn.rotation) as Rigidbody;
BossInstance.AddForce(Boss_spawn.forward * 5);
print(BossInstance.position.ToString());
Anima = Garand.GetComponent<Animation>();
Anima.Play(Fire);
StartCoroutine(DSTR());
}
if (Input.GetMouseButtonDown (0) && CurrentCartridge == 0 && Ended == false)
{
PlayerPrefs.SetInt("Fire" , 0);
Ended = true;
Anima = Garand.GetComponent<Animation>();
Anima.Play(End_Fire);
BossInstance = Instantiate(Boss, Boss_spawn.position, Boss_spawn.rotation) as Rigidbody;
BossInstance.AddForce(Boss_spawn.forward * 5);
StartCoroutine(Spwn());
}
}
void Ricarica()
{
if (Input.GetKeyDown(KeyCode.R) && CurrentCartridge == 0 && CurrentAmmo >0)
{
Garand.GetComponent<AudioSource>().clip = Reload;
Garand.GetComponent<AudioSource>().Play();
Anima = Garand.GetComponent<Animation>();
Anima.Play(Rel);
Ended = false;
if(CurrentAmmo < (MaxCartridge - CurrentCartridge))
{
CurrentCartridge = CurrentCartridge + CurrentAmmo;
CurrentAmmo = 0;
}
else
{
CurrentAmmo = (CurrentCartridge - MaxCartridge) + CurrentAmmo;
CurrentCartridge = MaxCartridge;
}
}
}
IEnumerator Spwn()
{
yield return new WaitForSeconds (0.9f);
RelInstance = Instantiate(Rel_, Boss_spawn.position, Boss_spawn.rotation) as Rigidbody;
RelInstance.AddForce(Boss_spawn.forward * 5);
}
void OnGUI()
{
GUI.Label(new Rect(A, B, 200, 190) , CurrentCartridge.ToString() + " | " + CurrentAmmo.ToString());
}
IEnumerator DSTR()
{
yield return new WaitForSeconds(5);
Destroy(BulletInstance);
Destroy(BossInstance);
}
}