Search Unity

how to add score after Destroing an object?

Discussion in 'Scripting' started by yurinkab, Feb 9, 2016.

  1. yurinkab

    yurinkab

    Joined:
    Dec 9, 2015
    Posts:
    7
    Hi!
    Im trying to make baby steps with C# and i started with a small game
    where you just pop zombie heads. Now, I want to be able to increase the count
    but i dont know how to connect between the script of the zombie "Destroy" and the main script where the
    score script is located.
    or if there is a simpler way I would be happy to know! :)

    Thanks!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    https://unity3d.com/learn/tutorials/projects/roll-a-ball/displaying-text?playlist=17141
    the approach in there is "playerscript keep counts"


    if you're after a central "gamemanager" approach you'll need to expose a function on your gamemanager script that takes a float/int and adds that to the score. The zombie can then get a reference to the gamemanager script using something like FindObjectOfType, then call that function when you call destroy.