- Home /
Transforming and playing particle effects? Help!
Updated: I changed some of the code around, and this is what it looks like now: This is the code I made to create and play the particle effect the particle effect:
public class PlayScript : MonoBehaviour
{
public GameObject delete;
public GameObject player;
private Projectile bullet;
private BulletDeleteSytem2 isDeleted;
public Rigidbody shrapnel;
public Transform BulletSpawn;
void Start()
{
delete = GameObject.Find("Bullet");
isDeleted = delete.GetComponent<BulletDeleteSytem2>();
player = GameObject.Find("FirstPersonPlayer");
bullet = player.GetComponent<Projectile>();
}
// Update is called once per frame
void Update()
{
if (bullet.BullEx)
{
Rigidbody clone;
clone = Instantiate(shrapnel, BulletSpawn.position, shrapnel.rotation);
Debug.Log("HasCreated");
bullet.BullEx = false;
Debug.Log("Works");
}
if (isDeleted.BullColl)
{
gameObject.GetComponent<ParticleSystem>().Play();
Debug.Log("HasPlayed");
}
transform.localPosition = BulletSpawn.position;
}
}
And this is the script that changes the variables in "playscript1"
public class BulletDeleteSytem2 : MonoBehaviour
{
Rigidbody rb;
public bool BullColl = false;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnCollisionEnter(Collision collision)
{
BullColl = true;
Debug.Log(BullColl);
Destroy(gameObject);
}
}
I hope this makes it easier to understand, as before it was a huge mess. Thanks to rh_galaxy for the advice of cleaning this code up
$$anonymous$$aybe you run Start() of your BulletDeleteSytem before object "Shrapne1" is created? Set a breakpoint here and see what info it gives you.
delete = GameObject.Find("Shrapnel");
Also I would advise you to somehow merge your unnamed first script with the PlayScript1-script, since they are identical in function.
Answer by N-8-D-e-v · Sep 13, 2020 at 07:42 PM
First off, BullColl is never being changed, so that could be your problem. Second, does your gameobject with the script attached have a particle system component attached?
BullColl is being changed in a separate bullet collision script that I have attached to the post above. That's my bad for not including it in the post and explaining in more detail what I'm doing. When the bullet is shot(The bullet is a separate object), it clones a particle effect with the play script attached in the same position as the bullet(Then its supposed to transform the position of the bullet with the bullet but it just doesn't )
would you $$anonymous$$d recording a video or something? Your code is kind of hard to read and make sense of
Can I send you images of the project files with relevant things highlighted?