playMaker

Author Topic: A variable for each object?  (Read 1934 times)

hellzer

  • Playmaker Newbie
  • *
  • Posts: 28
A variable for each object?
« on: May 14, 2015, 05:14:37 PM »
Im making a tower defence,wich include that enemies attack tower and tower have hp and they attack enemies.Enemies when there is no tower,they start attacking the base.When I create my tower from a prefab,they comme in [name](clone).I end up having 4 towers named tower(clone) normaly but they all use the same (HP) variable that I use for the prefab.When a monster kill a tower all the towers (die).My tower use float for hp and the monster substract float when they hit.I start strongly but now im lost,I dont know who is the problem and what should I do to make it simple....

Thank you for reading!!

redikann

  • Full Member
  • ***
  • Posts: 174
Re: A variable for each object?
« Reply #1 on: May 16, 2015, 08:59:43 PM »
You need to make sure the cloned prefabs are looking to themselves when making individual changes to variables. Let's say you have an object that flashes red when damaged. If multiple prefabs share this material and you make a call to that Material to flash red thru it's material.color setting all prefabs will probaly flash red. If you look to the prefab thru a  gameobject or object variable that references itself it will change only it's material.color.

hellzer

  • Playmaker Newbie
  • *
  • Posts: 28
Re: A variable for each object?
« Reply #2 on: May 17, 2015, 10:24:14 PM »
Thank you for your reply,so if im storing the object in a variable(not global) and then get the variable in this stored object(float for the hp) and subtrac it until death?

Tedthebug

  • Playmaker Newbie
  • *
  • Posts: 21
Re: A variable for each object?
« Reply #3 on: May 24, 2015, 07:43:34 AM »
When I've used prefabs for enemies with HP I created one enemy with all its local variables like HP & damage then when I use them the calls are made against each object as needed, so the one attacking does it's damage & if it gets hit the player damage is done against it's HP.