init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
44
Assets/Scripts/PlayerWeaponController.cs
Normal file
44
Assets/Scripts/PlayerWeaponController.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerWeaponController : MonoBehaviour
|
||||
{
|
||||
private GameObject weapon;
|
||||
public RawImage bulletBar;
|
||||
public float bullets = 11f;
|
||||
[HideInInspector]
|
||||
public float currentBullets;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
currentBullets = bullets;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
currentBullets = Mathf.Clamp(currentBullets, 0, bullets);
|
||||
if (Inventory.Items.Count > 0) {
|
||||
if (weapon==null || weapon.name != Inventory.getActiveItem().name) {
|
||||
if (weapon != null) {
|
||||
Object.Destroy(weapon);
|
||||
}
|
||||
weapon = Instantiate(Inventory.getActiveItem());
|
||||
weapon.name = Inventory.getActiveItem().name;
|
||||
weapon.transform.SetParent(gameObject.transform);
|
||||
weapon.transform.position = gameObject.transform.position;
|
||||
weapon.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
|
||||
Destroy(weapon.GetComponent<BoxCollider2D>());
|
||||
Destroy(weapon.GetComponent<Rigidbody2D>());
|
||||
}
|
||||
}
|
||||
bulletBar.transform.localScale = new Vector2(currentBullets, bulletBar.transform.localScale.y);
|
||||
if (Input.GetKeyDown(KeyCode.Mouse0) && currentBullets > 0) {
|
||||
weapon.GetComponent<Weapon>().shoot();
|
||||
currentBullets--;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue