07-30-2017, 07:14 AM
- PHP Source Code
- [/url]using UnityEngine;using System.Collections;
- [RequireComponent(typeof(Light), typeof(AudioSource))]
- public class Flashlight : MonoBehaviour {
- public AudioClip clickSound;
- public float batteryLifeInSec = 300f;
- public float batteryPercentage = 100;
-
- private bool on;
- private float timer;
- void Update() {
- Light lite = GetComponent<Light>();
- timer += Time.deltaTime;
-
- if(Input.GetKeyDown(KeyCode.F) && timer >= 0.3f && batteryPercentage > 0) {
- on = !on;
- audio.PlayOneShot(clickSound);
- timer = 0;
- }
-
- if(on) {
- lite.enabled = true;
- batteryPercentage -= Time.deltaTime * (100 / batteryLifeInSec);
- }
- else {
- lite.enabled = false;
- }
-
- batteryPercentage = Mathf.Clamp(batteryPercentage, 0, 100);
-
- if(batteryPercentage == 0) {
- lite.intensity = Mathf.Lerp(lite.intensity, 0, Time.deltaTime * 2);
- }
-
- if(batteryPercentage > 0 && batteryPercentage < 25) {
- lite.intensity = Mathf.Lerp(lite.intensity, 0.5f, Time.deltaTime);
- }
-
- if(batteryPercentage > 25 && batteryPercentage < 75) {
- lite.intensity = Mathf.Lerp(lite.intensity, 0.8f, Time.deltaTime);
- }
-
- if(batteryPercentage > 75 && batteryPercentage <= 100) {
- lite.intensity = Mathf.Lerp(lite.intensity, 1, Time.deltaTime);
- }
- [url=http://oyun-programlama.com/Thread/38826-el-feneri-scripti-unity/#codeLine_47_e3e531] } }
- [/url]using UnityEngine;using System.Collections;