Skip to content

Instantly share code, notes, and snippets.

@fallenblood7080
Last active February 18, 2023 15:47
Show Gist options
  • Save fallenblood7080/22896d76a3487ef8e9fd79bba2c552e5 to your computer and use it in GitHub Desktop.
Save fallenblood7080/22896d76a3487ef8e9fd79bba2c552e5 to your computer and use it in GitHub Desktop.
Bullet Trail Effect
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletTrailEffect : MonoBehaviour
{
[SerializeField] private GameObject bulletTrail;
public void CreateBulletTrail(Transform spawnPoint, Vector3 hitPoint)
{
GameObject clone = Instantiate(bulletTrail, spawnPoint.position, bulletTrail.transform.rotation);
moveTrail trail = clone.GetComponent<moveTrail>();
trail.hitpoint = hitPoint;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveTrail : MonoBehaviour
{
public Vector3 hitpoint;
public float timeNeededToReach;
public AnimationCurve curve;
void Start()
{
LeanTween.move(this.gameObject, hitpoint, timeneededToReach).setEase(curve);
Destroy(this.gameObject, timeNeededToReach + 0.01f);
}
}
[SerializeField] private Transform muzzle;
private BulletTrailEffect trailEffect;
//calling this function when shooting with raycast and pass the Raycast.point as second parameter
trailEffect.CreateBulletTrail(muzzle,hit.point);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment