1
This commit is contained in:
33
Assets/Plugins/Trails FX/Demo/Scripts/MoveObject.cs
Normal file
33
Assets/Plugins/Trails FX/Demo/Scripts/MoveObject.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TrailsFX.Demos {
|
||||
|
||||
public class MoveObject : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
Rigidbody rb = GetComponent<Rigidbody> ();
|
||||
if (rb == null)
|
||||
return;
|
||||
|
||||
Vector3 direction = Vector3.zero;
|
||||
if (Input.GetKey (KeyCode.A)) {
|
||||
direction = Vector3.right;
|
||||
}
|
||||
if (Input.GetKey (KeyCode.D)) {
|
||||
direction = Vector3.left;
|
||||
}
|
||||
if (Input.GetKey (KeyCode.W)) {
|
||||
direction = Vector3.back;
|
||||
}
|
||||
if (Input.GetKey (KeyCode.S)) {
|
||||
direction = Vector3.forward;
|
||||
}
|
||||
rb.AddForce (direction * 10);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
Assets/Plugins/Trails FX/Demo/Scripts/RotateObject.cs
Normal file
31
Assets/Plugins/Trails FX/Demo/Scripts/RotateObject.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TrailsFX.Demos {
|
||||
|
||||
public class RotateObject : MonoBehaviour
|
||||
{
|
||||
|
||||
public float speed = 100f;
|
||||
|
||||
Vector3 eulerAngles;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
SetAngles ();
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
transform.Rotate (eulerAngles * (Time.deltaTime * speed));
|
||||
if (Random.value > 0.995f) {
|
||||
SetAngles ();
|
||||
}
|
||||
}
|
||||
|
||||
void SetAngles ()
|
||||
{
|
||||
eulerAngles = new Vector3 (Random.value - 0.5f, Random.value - 0.5f, Random.value - 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
68
Assets/Plugins/Trails FX/Demo/Scripts/Shooter.cs
Normal file
68
Assets/Plugins/Trails FX/Demo/Scripts/Shooter.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TrailsFX.Demos {
|
||||
|
||||
public class Shooter : MonoBehaviour {
|
||||
|
||||
public float timeInterval = 0.3f;
|
||||
public GameObject[] bulletPrefabs;
|
||||
|
||||
Quaternion targetRot;
|
||||
float lastTargetTime;
|
||||
Vector3 lookAt, previousLookAt;
|
||||
GameObject[] bulletPool;
|
||||
int poolIndex;
|
||||
Vector3 startPos;
|
||||
|
||||
void Start() {
|
||||
startPos = transform.position;
|
||||
bulletPool = new GameObject[20];
|
||||
previousLookAt = Vector3.up;
|
||||
NewTarget();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
float deltaTime = Time.deltaTime;
|
||||
if (Vector3.Distance(startPos, transform.position) < 0.002f) {
|
||||
if (Time.time - lastTargetTime > timeInterval) {
|
||||
NewTarget();
|
||||
Shoot();
|
||||
}
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, deltaTime * 5f);
|
||||
} else {
|
||||
lastTargetTime = Time.time;
|
||||
}
|
||||
transform.position = Vector3.Lerp(transform.position, startPos, deltaTime * 4f);
|
||||
}
|
||||
|
||||
void NewTarget() {
|
||||
lookAt = new Vector3(Random.Range(-1f, 1f), Random.Range(0.5f, 1f), Random.Range(-1f, 1f));
|
||||
targetRot.SetFromToRotation(previousLookAt, lookAt);
|
||||
previousLookAt = lookAt;
|
||||
lastTargetTime = Time.time;
|
||||
}
|
||||
|
||||
void Shoot() {
|
||||
if (++poolIndex >= bulletPool.Length) {
|
||||
poolIndex = 0;
|
||||
}
|
||||
GameObject bullet = bulletPool[poolIndex];
|
||||
if (bulletPool[poolIndex] == null) {
|
||||
GameObject bulletPrefab = bulletPrefabs[Random.Range(0, bulletPrefabs.Length)];
|
||||
bullet = Instantiate<GameObject>(bulletPrefab);
|
||||
bulletPool[poolIndex] = bullet;
|
||||
}
|
||||
Vector3 cannonTip = transform.TransformPoint(new Vector3(0, 1.1f, 0));
|
||||
Vector3 direction = (cannonTip - transform.position).normalized;
|
||||
transform.position -= direction * 0.05f;
|
||||
bullet.transform.position = cannonTip;
|
||||
bullet.GetComponent<Rigidbody>().velocity = direction * (2f + Random.value);
|
||||
bullet.GetComponent<Renderer>().enabled = true;
|
||||
|
||||
TrailEffect trail = bullet.GetComponent<TrailEffect>();
|
||||
trail.Clear();
|
||||
trail.duration = 0.5f + (Random.value * 2f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user