Hi!
I haven’t found a way to make this work. The idea is as follows: The player controls a ship which has 4 empty gameObjects as children which work as “cannons”. What I want to do is to instantiate a Laser Prefab when the “Fire” key is pressed at those cannons gameObjects’ positions.
My code looks like this right now but it’s obviously not working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerFire : MonoBehaviour
{
[SerializeField] GameObject playerLaserPrefab;
Vector3 playerCannons;
void Start(){
playerCannons = gameObject.GetComponentInChildren<Transform>().position;
}
void OnFire(InputValue fireByPlayer){
if (fireByPlayer.isPressed){
Instantiate(playerLaserPrefab, playerCannons, Quaternion.identity);
}
}
}
Any answers will be kindly appreciated, thank you!