Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Why my score scirpt works on all of my prefabs?

I am making a game on topic "souls". I am using this script to update the score as long as the torch is lit up:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class ColorChanger : MonoBehaviour

{

 public GameObject flame;

 public GameObject flame1;

 public float score1 = 0f;

 public float score2 = 0f;


        void Awake ()

    {

        flame.SetActive(false);

        flame1.SetActive(false);

    }


    public void P1 ()

    {

        flame.SetActive(true);

        flame1.SetActive(false);

    }


    public void P2 ()

    {

       flame1.SetActive(true);

       flame.SetActive(false);

    }


    void Update ()

    {

        if (flame.activeInHierarchy == true)

        {

            score1 += 0.01f;

        }

        if (flame1.activeInHierarchy == true)

        {

            score2 += 0.01f;

        }

    }

    void OnCollisionEnter2D (Collision2D colliderInfo)

    {

        if (colliderInfo.collider.name == "Player1")

        {

            P1();

        }

        if (colliderInfo.collider.name == "Player2")

        {

            P2();

        }

    }

}


It updates but only when one specific torch is lit up. I want that if any of my torch prefab is lit up, then the score keeps updating. Also, if multiple torches are lit, then score is doubled and updates per second like this: (0, 2, 4, 6, 8, ...)

I would be very thankful for your help. If you need more information about the problem, ask it. I will reply it in the comments.

Answers

  • I want it work on all of my prefabs. Sorry, the question I posted above is a bit different as i forgot to put "not".

Sign In or Register to comment.