- Home /
instantiate particle effect dont work when i duplicate ganeobject
i have an particle effect of gun impact in the place the raycast from the gun is being hit, its work perfectly when i have 1 gun but when i duplicate the gun the instantiation does not work for both of the gun (no clone is being created), but other things like gun mechanics and other effects work just fine. i know that the raycast is working because i checked raycasthit.transform.name. any ideas why does it happen? the code (the lines are inside void shoot(), particlesystem G):
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class shooting : MonoBehaviour { public Transform shootpoint; public Animator anim; private leftgunattached isattachedtoleft; bool lastleftTrig = false; public ParticleSystem gunfire; public ParticleSystem Impacteffect; public static float pistolammo = 20; float magazineammo = 7; bool isreloading = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (magazineammo == 0 && isreloading == false && isattachedtoleft.isattached == true)
{
isreloading = true;
Invoke("reload", 2f);
}
anim.SetBool("IsShoot", false);
isattachedtoleft = gameObject.GetComponent<leftgunattached>();
if (isattachedtoleft.isattached == true)
{
if (lastleftTrig == false && Hand2Reciving.leftTrig == true)
{
if (magazineammo > 0)
{
shoot();
}
}
}
lastleftTrig = Hand2Reciving.leftTrig;
}
public void shoot()
{
magazineammo--;
anim.SetBool("IsShoot", true);
gunfire.Play();
int range = 100;
RaycastHit gunhit;
if (Physics.Raycast(shootpoint.position, shootpoint.forward, out gunhit, range))
{
ParticleSystem G = Instantiate(Impacteffect, gunhit.point, Quaternion.LookRotation(gunhit.normal));
Destroy(G.gameObject, 0.4f);
}
}
public void reload()
{
pistolammo = pistolammo - (7 - magazineammo);
if (pistolammo >= 0)
{
magazineammo = 7;
}
else
{
magazineammo += pistolammo + 7;
pistolammo = 0;
}
isreloading = false;
}
}
Your answer
Follow this Question
Related Questions
Checking if object intersects? 1 Answer
Instantiate rigidbody C# 1 Answer
Getting a component of an instantiated object returns an error 1 Answer