Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Electric : MonoBehaviour
- {
- [SerializeField, Range(0, 1f)] float om;
- public float voltage;
- [SerializeField] List<Electric> targets;
- [SerializeField] bool conts;
- [SerializeField] float contsvolt;
- private void Update()
- {
- if (voltage > 0.1f)
- {
- voltage *= om;
- }
- else
- {
- voltage = 0;
- }
- }
- void LateUpdate()
- {
- if (targets != null)
- {
- foreach (Electric target in targets)
- {
- if (voltage > target.voltage)
- {
- float tempvolt;
- tempvolt = voltage;
- voltage = Mathf.Lerp(voltage, target.voltage, Time.deltaTime*50f);
- target.voltage = Mathf.Lerp(target.voltage, tempvolt, Time.deltaTime * 50f);
- }
- }
- }
- if (conts)
- {
- voltage = contsvolt;
- }
- }
- void OnDrawGizmos()
- {
- UnityEditor.Handles.Label(transform.position, voltage.ToString());
- }
- private void OnCollisionEnter(Collision collision)
- {
- Electric item = collision.gameObject.GetComponent<Electric>();
- if (item!=null)
- {
- targets.Add(item);
- }
- }
- private void OnCollisionExit(Collision collision)
- {
- Electric item = collision.gameObject.GetComponent<Electric>();
- if (item != null)
- {
- targets.Remove(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement