Added things
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
//This code destroys the particle's GameObject once it's Start Time is over.
|
||||
public class AutoDestroyPS : MonoBehaviour
|
||||
{
|
||||
private float timeLeft;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
ParticleSystem system = GetComponent<ParticleSystem>();
|
||||
var main = system.main;
|
||||
timeLeft = main.startLifetimeMultiplier + main.duration;
|
||||
Destroy(gameObject, timeLeft);
|
||||
}
|
||||
|
||||
/*--------------------------bad variant------------------------
|
||||
public void Awake()
|
||||
{
|
||||
ParticleSystem system = GetComponent<ParticleSystem>();
|
||||
var main = system.main;
|
||||
timeLeft = main.startLifetimeMultiplier + main.duration;
|
||||
//Destroy(gameObject, main.startLifetimeMultiplier + main.duration);
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
timeLeft -= Time.deltaTime;
|
||||
if (timeLeft <= 0)
|
||||
{
|
||||
GameObject.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
-----------------------------------------------------------*/
|
||||
}
|
11
Assets/Arts/Hovl Studio/Toon Projectiles 2/Scripts/AutoDestroyPS.cs.meta
generated
Normal file
11
Assets/Arts/Hovl Studio/Toon Projectiles 2/Scripts/AutoDestroyPS.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 199e3c49ebcb3fe46997b10cf6a8eb52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileMover : MonoBehaviour
|
||||
{
|
||||
public float speed = 15f;
|
||||
public float hitOffset = 0f;
|
||||
public bool UseFirePointRotation;
|
||||
public Vector3 rotationOffset = new Vector3(0, 0, 0);
|
||||
public GameObject hit;
|
||||
public GameObject flash;
|
||||
private Rigidbody rb;
|
||||
public GameObject[] Detached;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
if (flash != null)
|
||||
{
|
||||
var flashInstance = Instantiate(flash, transform.position, Quaternion.identity);
|
||||
flashInstance.transform.forward = gameObject.transform.forward;
|
||||
var flashPs = flashInstance.GetComponent<ParticleSystem>();
|
||||
if (flashPs != null)
|
||||
{
|
||||
Destroy(flashInstance, flashPs.main.duration);
|
||||
}
|
||||
else
|
||||
{
|
||||
var flashPsParts = flashInstance.transform.GetChild(0).GetComponent<ParticleSystem>();
|
||||
Destroy(flashInstance, flashPsParts.main.duration);
|
||||
}
|
||||
}
|
||||
Destroy(gameObject,5);
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (speed != 0)
|
||||
{
|
||||
rb.velocity = transform.forward * speed;
|
||||
//transform.position += transform.forward * (speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
//https ://docs.unity3d.com/ScriptReference/Rigidbody.OnCollisionEnter.html
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
//Lock all axes movement and rotation
|
||||
rb.constraints = RigidbodyConstraints.FreezeAll;
|
||||
speed = 0;
|
||||
|
||||
ContactPoint contact = collision.contacts[0];
|
||||
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
|
||||
Vector3 pos = contact.point + contact.normal * hitOffset;
|
||||
|
||||
if (hit != null)
|
||||
{
|
||||
var hitInstance = Instantiate(hit, pos, rot);
|
||||
if (UseFirePointRotation) { hitInstance.transform.rotation = gameObject.transform.rotation * Quaternion.Euler(0, 180f, 0); }
|
||||
else if (rotationOffset != Vector3.zero) { hitInstance.transform.rotation = Quaternion.Euler(rotationOffset); }
|
||||
else { hitInstance.transform.LookAt(contact.point + contact.normal); }
|
||||
|
||||
var hitPs = hitInstance.GetComponent<ParticleSystem>();
|
||||
if (hitPs != null)
|
||||
{
|
||||
Destroy(hitInstance, hitPs.main.duration);
|
||||
}
|
||||
else
|
||||
{
|
||||
var hitPsParts = hitInstance.transform.GetChild(0).GetComponent<ParticleSystem>();
|
||||
Destroy(hitInstance, hitPsParts.main.duration);
|
||||
}
|
||||
}
|
||||
foreach (var detachedPrefab in Detached)
|
||||
{
|
||||
if (detachedPrefab != null)
|
||||
{
|
||||
detachedPrefab.transform.parent = null;
|
||||
}
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
11
Assets/Arts/Hovl Studio/Toon Projectiles 2/Scripts/ProjectileMover.cs.meta
generated
Normal file
11
Assets/Arts/Hovl Studio/Toon Projectiles 2/Scripts/ProjectileMover.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 605a456cfc02f6b499a64717539a27e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user