- Home /
Question by
DreamerScreamer · Apr 18 at 09:25 PM ·
c#unity 2d
Particle appear once in the start even if Play on Awake is disabled,Particle System triggers once at start even if play on awake disabled
Hi everyone and thanks for help too much! I've created a trail using particle system. It works nice but it spawn one particle right when I start the game. I disabled play on awake function, I think it happens because I have that line in code void CreateTrail() { trail.Play(); }
but in the video which I found is the same code but there is no such problem.
here the full code and trail creation is in the end.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
public Animator animator;
public float movespeed = 5f;
public Rigidbody2D rb;
Vector2 move;
public ParticleSystem trail;
void CreateTrail()
{
trail.Play();
}
private void Awake()
{
animator = GetComponent<Animator>();
}
void Update()
{
move.x = Input.GetAxisRaw("Horizontal");
move.y = Input.GetAxisRaw("Vertical");
AnimatePlayer();
}
void FixedUpdate()
{
rb.MovePosition(rb.position + move * movespeed * Time.fixedDeltaTime);
}
private void AnimatePlayer()
{
if (move != Vector2.zero)
{
animator.SetBool("isMoving", true);
}
else
{
animator.SetBool("isMoving", false);
CreateTrail();
}
}
}
Comment