Hello, i have prefab that spawns on Start and follows the player. the player game object has a particle system that works perfectly. I tried to do the same thing for the prefab, but it wont work. I want it to have particles while the prefab exists. I cant find any similar threads for my problem.
Thanks for any response.
Here is the code for the prefab:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyfollow : MonoBehaviour
{
public float speed;
private Transform target;
public Rigidbody2D rb2;
public ParticleSystem ps1;
// Start is called before the first frame update
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
GetComponent<Rigidbody2D>();
GetComponent<ParticleSystem>();
}
// Update is called once per frame
void Update()
{
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
rb2.velocity = Vector2.zero;
partikels();
}
void partikels()
{
ps1.Play();
}
}