- Home /
Instantiate prefabs between two characters
Hi guys,
I'd like to know how I could instantiate prefabs between two characters in my game. It's a tactical RPG and one of the characters uses a flame thrower as a weapon. When he shoots at the other characters I want to instantiate the flames in the tiles which separate them, as you can see in the image:
I've already tried something like this, but unfortunately I couldn't succeed in my attempt. I attached this code to the one who shoots the flames:
public void SheriffShooting()
{
for (int i = 0; i < Characters.Length; i++)
{
if (Characters[i].tag == "Sheriff" && Input.GetMouseButtonDown(1) && Characters[i].GetComponent<Player>().isPlayer)
{
//raycast checks and returns an object, if it's a tile, the unit shoots
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//checks if the tile is available based on the line and column of the unit
Tile tileAux = hit.transform.gameObject.GetComponent<Tile>();
Player scriptPlay = player.GetComponent<Player>();
if (tileAux.TilePostion.x == scriptJog.GridPosition.x || tileAux.TilePostion.y == scriptJog.GridPosition.y)
{
if (tileAux.TilePostion.x > scriptJog.GridPosition.x)
tileAux.TilePostion.x = 5;
else
tileAux.TilePostion.x = 0;
if (tileAux.TilePostion.y > scriptJog.GridPosition.y)
tileAux.TilePostion.y = 5;
else
tileAux.TilePostion.y = 0;
//instantiates the flames
GameObject FLameGun = Instantiate(Flames, SpawFire.transform.position, SpawFire.transform.rotation);
Rigidbody FlameRigid = FlameGun.GetComponent<Rigidbody>();
FlameRigid.velocity = SpawFire.transform.forward * FlameVeloc * Time.deltaTime;
}
}
}
}
}
Any idea guys how I could solve it? I think I could use a vector.lerp to do it, but I don't know.
Answer by Naggil · Nov 20, 2019 at 04:48 PM
if u just want to instantiate it between them u can use
Vector3.Lerp(PositionA, PositionB, 0.5f);
it will return the middle position between the 2 vectors
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UnityEngine.Android not does not exist 0 Answers
Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e) 0 Answers
,How to stop jump animtion 1 Answer