Hello Chris,
Since this is the first time writing here I'm gonna start by saying congratulation for this amazing tool kit.
Now, on to my problem
What I'm trying to do is this:
- Place an object in the scene
- The character interacts with the object
- That object is destroyed
The catch is that I want to duplicate that object as many times as I want and the behavior to remain the same.
Using the Actions from AC, I can delete the object using Object - Add/Remove, but the gameobject field doesn't update when I duplicate the object.
I've thought of a work around, but I'm having some problems with this one too.
I thought of using Object -> SendMessage and send a message to a script that is in the Action. The script would then delete the object attached in it, since the gameobject field from the script updates after I duplicate the object. The problem here is that I don't know how to send a message using the Action from AC and still make it work after I duplicate the object, since SendMessage uses the same method as Object - Add/Remove from above.
Btw, I'm still learning C#, so I mostly know the basic commands and stuff.
Thanks a lot and hope you can help me with this.
Comments
If you need to reference GameObjects that are not in the scene, you will need to reference their Constant ID number instead.
Try dragging the prefab of the GameObject into your "Object: Add or remove" Action instead - it will generate a new ConstantID number for you, which will show up beneath the GameObject field. When you switch scene or re-start Unity, the field will be empty again, but the number will still show. This is how AC keeps track of objects that are not in the same scene as your Action.
Your specific requirement of removing the last-used object is heavily-tailored to your game, so I would say that a custom Action to do this is what you'd want. Custom Actions allow you to do basically anything, so I'd recommend you look into them.
You can get the currently-active Hotspot with the following C# command:
AC.Hotspot currentHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
So, to get the most recent Hotspot, you'd want something like this in a C# script's Update function:
AC.Hotspot lastHotspot;
void Update ()
{
AC.Hotspot currentHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
if (currentHotspot != null)
{
lastHotspot = currentHotspot;
}
}
You can then retrieve the value of lastHotspot in your custom Action in order to destroy it.
You can see the entry for the PlayerInteraction's GetActiveHotspot function in the scripting guide, as well as all of AC's public functions and variables.