Post by uberwiggett on Aug 24, 2018 4:36:45 GMT
Hi guys, so playing around with a mash up of assets I managed to get a simple activate to spawn system together for Invector. I am using Emerald AI with this one, but you can spawn any prefab including the new Beta Ai from invector. Handy if you're working on any RTS style elements to your game. Demonstration video below;
Currently it is set up to only allow you to spawn on activating the object, however down the line I will expand this to allow for checking against the player inventory for the necessary components or an alternative inventory for them. For now though it's just a simple script to instantiate the object on command, and using the action trigger from invector to call the method.
First you will need the script, I took this one from an online post and modified it accordingly,
For future utility, it actually stores the info of the objects it's spawned, which is good for me because I will be tracking the characters, but for now it's not super relevant.
next you will need to place the script onto an object, technically any game object but I put mine on the object I will be using to spawn (eg a barracks) then drop the prefab you want to spawn into the field, as well as the transform you want to use for the spawn point.
Next you will need to place a trigger generic action script on the interaction object you want to use for the player to spawn the prefabs. Ensure you also have a "v generic action" component on your player.
as above, ensure that in the "on do action" section has the instantiate script you want to use. You can run multiple of these without clashing into each other by assigning the correct prefabs to the correct places.
TODO:
Currently it is set up to only allow you to spawn on activating the object, however down the line I will expand this to allow for checking against the player inventory for the necessary components or an alternative inventory for them. For now though it's just a simple script to instantiate the object on command, and using the action trigger from invector to call the method.
First you will need the script, I took this one from an online post and modified it accordingly,
For future utility, it actually stores the info of the objects it's spawned, which is good for me because I will be tracking the characters, but for now it's not super relevant.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
// rename this class to suit your needs
public class TestInstantiation : MonoBehaviour
{
// the Equip prefab - required for instantiation
public GameObject equipPrefab;
public GameObject spawnPoint;
// list that holds all created objects - deleate all instances if desired
public List<GameObject> createdObjects = new List<GameObject>();
public void CreateObject()
{
// a prefab is need to perform the instantiation
if (equipPrefab != null)
{
// instantiate the object
Vector3 spawnLoc = spawnPoint.transform.position;
GameObject go = (GameObject)Instantiate(equipPrefab, spawnLoc, Quaternion.identity);
createdObjects.Add(go);
}
}
}
next you will need to place the script onto an object, technically any game object but I put mine on the object I will be using to spawn (eg a barracks) then drop the prefab you want to spawn into the field, as well as the transform you want to use for the spawn point.
Next you will need to place a trigger generic action script on the interaction object you want to use for the player to spawn the prefabs. Ensure you also have a "v generic action" component on your player.
as above, ensure that in the "on do action" section has the instantiate script you want to use. You can run multiple of these without clashing into each other by assigning the correct prefabs to the correct places.
TODO:
- Optimise code: The vector 3 call can probably be done elsewhere just once on start.
- Implement resource requirement for running create method.
- Add code to check for necessary resource from third party storage.
- Add code to check for necessary resource from Invector Player Inventory.