Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public var raycastLength : int = 5; //How far away can you be to pick up the battery?
- public var batteryIncrease : float = 1.0; //How much power do you get by one battery?
- public var batteryObjectName : String = "Battery"; //Must be the same name as the battery in the scene or it won't work.
- //Importing the "Player_Toggle_Flashlight"
- public var flashlight : GameObject;
- private var ptf_Script : Player_Toggle_Flashlight;
- //Audio
- public var mainPlayer : Transform;
- public var pickupSound : AudioClip;
- //Variables END
- function Start()
- { //Get the script Player_Toggle_Flashlight
- ptf_Script = flashlight.GetComponent(Player_Toggle_Flashlight);
- }
- function Update()
- { //Pick up the battery
- BatteryPickup();
- }
- //Function for picking up the battery
- function BatteryPickup()
- { //If i press E, then something happens
- if(Input.GetKeyDown(KeyCode.E))
- {
- //Where will the ray start? Camera --> main --> ScreenPointToRay vector3(3d)
- var rayOrigin = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0.0));
- var hit : RaycastHit;
- //
- if(Physics.Raycast (rayOrigin, hit, raycastLength))
- { //If Raycast hit the gameObject named batteryObjectName(Battery), refer to variables
- if(hit.collider.gameObject.name == batteryObjectName)
- { //Then the var batteryLife inside the pft_script = batteryLife + batteryIncrease
- ptf_Script.batteryLife += batteryIncrease;
- //Then destroy the object
- Destroy(hit.collider.gameObject);
- //Then play the sound of pick up battery (pickupSound)
- //audio.PlayClipAtPoint(pickupSound, mainPlayer.position);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement