Last active
February 18, 2023 15:47
-
-
Save fallenblood7080/22896d76a3487ef8e9fd79bba2c552e5 to your computer and use it in GitHub Desktop.
Bullet Trail Effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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