hi i am new to c #, i would like to implement this: there is a script that clones the q object at random points when pressed. I wish that every time I click on the q object, +1 point is added and the score is recorded on the screen.
thanks in advance
script added below
object spawn:
public GameObject qPrefab;
public Vector3 center;
public Vector3 size;
internal bool lose;
public bool next { get; internal set; }
void Update()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null)
{
if (hit.collider)
{
if (hit.collider.tag == "q")
{
if (Input.GetMouseButtonDown(0))
{
SpawnNextq();
}
}
}
}
}
void SpawnNextq()
{
Vector3 pos = center + new Vector3(Random.Range(-size.x / 2, size.x / 2),
Random.Range(-size.y / 2, size.y / 2),
0);
Instantiate(qPrefab, pos, Quaternion.identity);
Destroy(gameObject);
}
scoring:
public void OnClick()
{
score++;
xText.text = score +"";
}