Particle System does not support multiple Materials on Mesh in Renderer

image

and since my Arrow from the Asset Pack uses 2 Materials

image

…I needed to have a different approach.

(after many hours of failed attempts)

The Weapon is Instantiating Projectiles

image

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class TargetLocator : MonoBehaviour
{
    [Header("Weapon and Projectile")]
    [SerializeField] private Transform weapon;
    [SerializeField] private Transform projectileSpawnPoint;
    [SerializeField] private float weaponFireRate;
    [SerializeField] private Projectile projectile;

    private Transform target;
    private float fireRateTimer;

    private void Start() {
        target = FindObjectOfType<EnemyMover>().transform;
        fireRateTimer = weaponFireRate;
    }

    private void Update() {
        AimWeapon();
        CheckFireRate();
    }

    private void AimWeapon() {
        weapon.LookAt(target);
    }

    private void CheckFireRate() {
        // if the arrow is available
        if (fireRateTimer < weaponFireRate) {
            fireRateTimer += Time.deltaTime;            
        } else {
            Shoot();
            fireRateTimer = 0f;            
        }                  
    }

    private void Shoot() {
        Instantiate(projectile.gameObject, projectileSpawnPoint.position, projectileSpawnPoint.rotation);    
    }
}

and the Projectiles have Translation on them

image

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Projectile : MonoBehaviour
{    
    [SerializeField] private float projectileSpeed;
        
    private void Update() {
        Fly();
    }

    private void Fly() {
        transform.Translate(Vector3.forward * projectileSpeed * Time.deltaTime);
    }
    
    private void OnTriggerEnter(Collider other) {        
        Destroy(gameObject);
    }
}

Works now <3

1 Like

Good stuff. I’m a little confused as to why you were creating projectiles with a particle system, though…

PS. Those assets are looking clean!

The Realm Rush (Unity 3D) course uses a Particle System in the video to spawn projectiles.

That’s the reason for my subject.

Just had a look at it and saw. Not something I would have done.

1 Like

Privacy & Terms