Quantcast
Channel: Answers by "CallToAdventure"
Viewing all articles
Browse latest Browse all 48

Answer by Airship Games

$
0
0
I tried something - well, various avenues) and I keep bumping into C# and Js - I know a bit more of the latter and the original perlin noise lighting script is in C# so I am not sure what I am doing. Here's what I did so far - it doesn't seem to do anything but at least I am not getting any errors. Initially - since the gun is a child object of the Camera - I got some errors there, fixed with camera changed to Camera.main. Clear head in the morning may let me see this in a more optimistic light :) using UnityEngine; using System.Collections; public class LightningGun : MonoBehaviour { public Transform target = null; public int zigs = 100; public float speed = 1f; public float weaponRange = 20f; public float scale = 1f; public Light startLight; public Light endLight; public AudioClip projectileSound; Perlin noise; float oneOverZigs; private Particle[] particles; void Start() { oneOverZigs = 1f / (float)zigs; particleEmitter.emit = false; particleEmitter.Emit(zigs); particles = particleEmitter.particles; } void Fire () { if (target == null) { Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit, weaponRange)) if (hit.transform.tag == "EnemyShip") { target = hit.transform; if (noise == null) noise = new Perlin(); float timex = Time.time * speed * 0.1365143f; float timey = Time.time * speed * 1.21688f; float timez = Time.time * speed * 2.5564f; for (int i=0; i < particles.Length; i++) { Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i); Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z), noise.Noise(timey + position.x, timey + position.y, timey + position.z), noise.Noise(timez + position.x, timez + position.y, timez + position.z)); position += (offset * scale * ((float)i * oneOverZigs)); particles[i].position = position; particles[i].color = Color.white; particles[i].energy = 1f; } audio.clip = projectileSound; audio.Play(); particleEmitter.particles = particles; if (particleEmitter.particleCount >= 2) { if (startLight) startLight.transform.position = particles[0].position; if (endLight) endLight.transform.position = particles[particles.Length - 1].position; } } else target = null; } } }

Viewing all articles
Browse latest Browse all 48

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>