i3e-asg2/Assets/Scripts/GunPickable.cs

44 lines
1 KiB
C#
Raw Permalink Normal View History

2024-07-01 03:11:10 +00:00
using System.Collections;
using System.Collections.Generic;
2024-07-04 17:22:55 +00:00
using TMPro;
2024-07-01 03:11:10 +00:00
using UnityEngine;
public class GunPickable : Pickable
{
private bool InHand;
public override void Start()
{
base.Start();
gameObject.GetComponent<Gun>().enabled = false;
}
public override void Interact()
2024-07-01 03:11:10 +00:00
{
base.Interact();
2024-07-01 03:11:10 +00:00
gameObject.GetComponent<Gun>().enabled = true;
2024-07-04 17:22:55 +00:00
gameObject.GetComponent<AudioSource>().PlayOneShot(GameManager.instance.handling);
2024-07-01 03:11:10 +00:00
InHand = true;
}
public override void Drop()
{
base.Drop();
gameObject.GetComponent<Gun>().enabled = false;
2024-07-04 17:22:55 +00:00
GameObject.Find("bullet counter").GetComponent<TextMeshProUGUI>().text="";
2024-07-01 03:11:10 +00:00
InHand = false;
}
public override void Update()
2024-07-01 03:11:10 +00:00
{
if (InHand)
{
Vector3 currentRotation = transform.eulerAngles;
currentRotation.x = Camera.transform.eulerAngles.x;
transform.eulerAngles = currentRotation;
}
base.Update();
2024-07-01 03:11:10 +00:00
}
2024-07-01 03:11:10 +00:00
}