using UnityEngine;
using System.Collections;
public class BottleThrowPointController : MonoBehaviour
{
void Start(){
PlayerPrefs.DeleteAll();
Load_powerup_1_1();
Debug.Log(bought_toggle_val_powerup_1_1);
}
public bottleMovement[] bottles; // list of bottles to instantiate
public GUIStyle Inv_button;
Rect rect_inventory = new Rect(Screen.width*93/100, Screen.height*1/100, Screen.width/12, Screen.height/8);
public GUIStyle inv_main_window_button;
public GUIStyle inv_main_window;
//Rect rect_inv_main_window = new Rect(Screen.width*10/100, Screen.height*10/100, Screen.width-Screen.width*20/100, Screen.height-Screen.height*20/100);
Rect rect_inv_main_window = new Rect(100,100,200,200);
//Rect rect_inv_main_window = new Rect(hosizontal position,vertical position,size-horizontal,size vertical);
public Vector2 scrollPosition;
float scrollSpeed = 3;
public GUIStyle toggle_style;
private bool toggle_val = false;
bool open_Inventory_Window = false;
public static int toggle_val_powerup_1_1=10;
public static bool bought_toggle_val_powerup_1_1=false;
public static string save_powerup_1_1;
void OnGUI(){
//Debug.Log(toggle_val);
GUI.skin.button = Inv_button;
GUI.skin.window = inv_main_window;
// this button is just used to show the image and nothing else
if (GUI.Button(new Rect(Screen.width*93/100, Screen.height*1/100, Screen.width/12, Screen.height/8), "")){
Debug.Log("Clicked the button with text");
}
GUI.Box(rect_inventory, "someText");
if(open_Inventory_Window==true)
rect_inv_main_window = GUI.Window(2, rect_inv_main_window, DoMyWindow2, "");
//main Inventory power up window
}
//
// Update is called once per frame
void Update ()
{
scrollPosition.x += Input.GetAxis("Horizontal") * scrollSpeed;
scrollPosition.y -= Input.GetAxis("Vertical") * scrollSpeed;
if (!rect_inventory.Contains( new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 1))) {
if (Input.GetMouseButtonDown(0) Time.timeScale!=0)
{
if ( Input.mousePosition.x > Screen.width/2 )
SpawnBottle( BottleDirection.RIGHT );
else
SpawnBottle( BottleDirection.LEFT );
Debug.Log("outside rect");
}
}
else if (rect_inventory.Contains( new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 1))) {
if (Input.GetMouseButtonDown(0)){
Time.timeScale = 0.0f; // paused the game
open_Inventory_Window = true;
Debug.Log("inside rect");
}
}
// if (Input.GetMouseButtonDown(0))
// {
//
// if ( Input.mousePosition.x > Screen.width/2 )
// SpawnBottle( BottleDirection.RIGHT );
// else
// SpawnBottle( BottleDirection.LEFT );
//
// }
}
void SpawnBottle( BottleDirection direction )
{
//as the prefab is of type BottleMovement, it'll return a BottleMovement
bottleMovement newBottle = Instantiate(bottles[0],transform.position, Quaternion.identity)as bottleMovement;
//set the side it shall move
newBottle.direction = direction;
}
void DoMyWindow2(int windowIDE) {
// scrollPosition = GUI.BeginScrollView(rect_inv_main_window, scrollPosition, new Rect(Screen.width*5/100, Screen.height*5/100, Screen.width-Screen.width*15/100, Screen.height-Screen.height*15/100));
scrollPosition = GUI.BeginScrollView(new Rect(10,20,rect_inv_main_window.width*0.9f, rect_inv_main_window.height - 20), scrollPosition, new Rect(0, 0, 50,Screen.height));
// scrollPosition = GUI.BeginScrollView(new Rect(10,20,rect_inv_main_window.width * 0.5f, rect_inv_main_window.height - 40), new Vector2(scrollPosition.x, MyTouchInput.touchPosition.y), new Rect(0, 0, 50,Screen.height));
GUI.skin.button = inv_main_window_button;
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*20/100+10, 20, 20), "x1");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*30/100+10, 20, 20), "x2");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*40/100+10, 20, 20), "x3");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*50/100+10, 20, 20), "x4");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*60/100+10, 20, 20), "x5");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*70/100+10, 20, 20), "x6");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*80/100+10, 20, 20), "x7");
// GUI.Button(new Rect(Screen.width*20/100, Screen.height*80/100+10, 20, 20), "x8");
GUI.Button(new Rect(0, 10, 100, 40), "x1");
GUI.Button(new Rect(0, 60, 100, 40), "x2");
GUI.Button(new Rect(0, 110, 100, 40), "x3");
GUI.Button(new Rect(0, 160, 100, 40), "x4");
GUI.Button(new Rect(0, 210, 100, 40), "x5");
GUI.Button(new Rect(0, 260, 100, 40), "x6");
GUI.Button(new Rect(0, 310, 100, 40), "x7");
GUI.EndScrollView();
// close button
if (GUI.Button(new Rect(Screen.width*75/100+10, Screen.height*70/100+10, 20, 20), "x")){
open_Inventory_Window=false;
Time.timeScale = 1.0f;
Debug.Log("Clicked the button with text");
}
// 114 - 129 code for toggle
// GUI.skin.toggle = toggle_style;
//
// // step1:: disable it, and only enable it if highscore [total coins] value is greater than 200
// GUI.enabled=false;
// Debug.Log(bought_toggle_val_powerup_1_1);
// if(scoreHandler._highscore>toggle_val_powerup_1_1 bought_toggle_val_powerup_1_1==false){
// GUI.enabled=true;
// if(toggle_val==true){
// Debug.Log(toggle_val);
// bought_toggle_val_powerup_1_1=true;
// GUI.enabled=false;
// Save_powerup_1_1();
// }
//
// }
// toggle_val = GUI.Toggle(new Rect(10, 10, 25, 25),toggle_val, "");
}
// public static void Save_powerup_1_1(){
//PlayerPrefs.SetInt("save_powerup_1_1", bought_toggle_val_powerup_1_1 ? 1 : 0);
//}
// public static void Load_powerup_1_1(){
// bought_toggle_val_powerup_1_1 = PlayerPrefs.GetInt("save_powerup_1_1") == 1 ? true : false;
// }
public static void SetBool(string Name, bool value)
{
PlayerPrefs.SetInt(Name, value ? 1 : 0);
}
public static bool GetBool(string Name, bool _default = false)
{
if (PlayerPrefs.HasKey(Name))
{
return PlayerPrefs.GetInt(Name) == 1;
}
return _default;
}
public static void Save_powerup_1_1(){
SetBool("save_powerup_1_1", bought_toggle_val_powerup_1_1);
}
public static void Load_powerup_1_1(){
bought_toggle_val_powerup_1_1 = GetBool("save_powerup_1_1");
}
}