basically I’ve got a system set up for the player to pick what abilities they want to use in their run from the main menu and they get sent as a static list to a player script I use for instantiating the abilities. however they don’t all appear at the same location, meaning I need a different vector location for each ability (unless they do spawn in the same place but I’ve only made two so far). I’m not sure how to efficiently get these vectors as the two i’m using right now for testing are both based on the player’s location and i’m not sure how else to do it besides doing something like transform.position-ing the ability right after it spawns, cause I’m worried doing so could risk a delay from using it to it actually activating. I’d be appreciative for any ideas.
Edit: to provide additional info on my situation per request; to provide an example of where I’m spawning abilities. My first ability, we’ll call it SlashCombo, spawns a short distance in front of the player. the line for getting this vector is 26 “SpawnLoc = aimPos + aimDir * 0.9f;” and as long the abilities being performed is the SlashCombo it will spawn at the appropriate place. However my other combo, we’ll refer to has “GroundSlam”, should be spawned directly on the player. The way I have it set up, the player picks up to 5 abilities in any order they choose, which are added to the previously mentioned static list via button press. I intend to keep adding more abilities to the game over time so different abilities will be in different places on the list. So since I won’t know what ability will be where on the list, and different abilities will be spawned at different locations (the SlashCombo and GroundSlam example) I’m trying to solve how to provide the instantiate with the correct vector on a per ability basis.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ComboTriggerScript : MonoBehaviour
{
public Transform AimTransform;
public GameObject Projectile;
public List<GameObject> CurrentCombos;
private Vector2 SpawnLoc;
[SerializeField]
private int TriggerCount = 1;
// Start is called before the first frame update
void Start()
{
CurrentCombos = SelectedCombosStorage.SelectedCombos;
}
// Update is called once per frame
void Update()
{
Vector2 aimPos = AimTransform.position;
Vector2 aimDir = AimTransform.right;
Quaternion aimRot = AimTransform.rotation;
SpawnLoc = aimPos + aimDir * 0.9f; //this is the spawning thing to spawn the object a short ways infront of the player.
// SpawnLoc = transform.position; //this should spawn the gameobject direction on the player, for the Groundslam around the player combo.
}
private void FixedUpdate()
{
if (Input.GetAxis("Combo 1") > 0 && TriggerCount > 0) //these are the checks for input for each combo
{
Instantiate(CurrentCombos[0], SpawnLoc, Quaternion.identity);
TriggerCount--;
StartCoroutine(Cooldown());
}
else if (Input.GetAxis("Combo 2") > 0 && TriggerCount > 0 && CurrentCombos.Count >= 2)
{
Instantiate(CurrentCombos[1], SpawnLoc, Quaternion.identity);
TriggerCount--;
StartCoroutine(Cooldown());
}
else if (Input.GetAxis("Combo 3") > 0 && TriggerCount > 0 && CurrentCombos.Count >= 3)
{
Instantiate(CurrentCombos[2], SpawnLoc, Quaternion.identity);
TriggerCount--;
StartCoroutine(Cooldown());
}
else if (Input.GetAxis("Combo 4") > 0 && TriggerCount > 0 && CurrentCombos.Count >= 4)
{
Instantiate(CurrentCombos[3], SpawnLoc, Quaternion.identity);
TriggerCount--;
StartCoroutine(Cooldown());
}
else if (Input.GetAxis("Combo 5") > 0 && TriggerCount > 0 && CurrentCombos.Count >= 5)
{
Instantiate(CurrentCombos[4], SpawnLoc, Quaternion.identity);
TriggerCount--;
StartCoroutine(Cooldown());
}
}
private IEnumerator Cooldown()
{
yield return new WaitForSeconds(1);
TriggerCount = 1;
yield return new WaitForSeconds(0);
}
}
P.S. my game is 2d if that helps…