I am trying to get the integer "pop" from the first script and the integer "clack" to be added together so that they can become a text that is the score for my game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BlueGun : MonoBehaviour
{
public float bluedamage = 10f;
public float bluerange = 100f;
public Text ScoreText;
public int pop = 0;
public Camera fpsCam;
void start()
{
ScoreText.text = pop.ToString();
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
Shoot();
}
public void Shoot ()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, bluerange));
{
Blue blue = hit.transform.GetComponent<Blue>();
if (blue != null)
{
blue.inquirehealth(bluedamage);
pop++;
ScoreText.text = pop.ToString();
}
}
}
}
This ^^ above is the integer for "pop." I understand that it turns it into a string at the end, making the adding aspect a bit more difficult. So maybe, I shouldn't do it that way. And So I am wondering how I can add these two integers on completely different scripts so I can convert them to a text for the score. I know how to do the conversion part, what I don't know is how to acquire the two integers to add them. Thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GunRay : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
float fire;
public Text ScoreTextred;
public int clack = 0;
public Camera fpsCam;
void start()
{
ScoreTextred.text = clack.ToString();
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
Shoot();
}
public void Shoot ()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range) && hit.transform.tag == "Red");
{
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
clack++;
ScoreTextred.text = clack.ToString();
}
}