Is there any way to increase score with UI when I destroy an object?
Hey guys, I am a code and unity newbie. As I am doing this for my class as a final project, I want to make the best I could. Unfortunately, I am stuck at this moment on how to figure out keeping score up when destroying objects. Here are my file and scripts. Btw scripts are from YouTube tutorial by Brackeys
https://drive.google.com/drive/folders/1tzw555e-Ky3Q59spcarjFyndpkEMy0d4?usp=sharing
using UnityEngine;
public class gunscript : MonoBehaviour { public float damage = 10f; public float range = 100f;
public Camera fpsCam;
public ParticleSystem paint_stream;
public GameObject impactEffect;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot ()
{
paint_stream.Play();
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGO, 2f);
}
}
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 50f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
How to display random questions without repeating the previous? 2 Answers
Inherance script problem [C#] 0 Answers
Performance Issue While Near One Specific Object 0 Answers
Toggling Script from another GameObject on/off Correctly using Unity Input System 1 Answer
Taking continuously damage on a surface 0 Answers