// Use this for initialization void Start() { action_state = p_state.waiting; throw_power = default_throw_power; throw_angle = Vector3.Angle(transform.forward, new Vector3(transform.forward.x, 0, transform.forward.z)); throw_arc = gameObject.AddComponent <LineRenderer>(); throw_arc.SetWidth(0f, .1f); throw_arc.enabled = false; player = GameObject.FindGameObjectsWithTag("Player")[0]; player_pickup = player.GetComponent <PickUp>(); //GameObject wheel = GameObject.FindGameObjectsWithTag("UI")[0]; //ui_wheel = wheel.GetComponent<UIWheelController>(); }
// Update is called once per frame void Update() { offset = gameObject.transform.position + gameObject.transform.forward * 3f + gameObject.transform.right / 2f + gameObject.transform.up * 3f; // fake position, we'll change this ??? //print("In Throw.cs: " + player_pickup.Inventory_items.Count); if (player_pickup.Inventory_items.Count != 0) { //print(player_pickup.Inventory_items.Count); if (Input.GetMouseButtonDown(1) && player_pickup.Inventory_items.Count != 0) { //print("In Throw.cs: ok trying to hold an item now when inventory.count = " + player_pickup.Inventory_items.Count); //GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); //print("In Throw.cs: item_index = " + item_index); if (item_index >= player_pickup.Inventory_items.Count) { item_index -= player_pickup.Inventory_items.Count; } player_pickup.Inventory_items[item_index].SetActive(true); holdObjectToThrow(player_pickup.Inventory_items[item_index]); //held_item_.transform.GetChild(0).gameObject.SetActive(false); throw_power = default_throw_power; throw_angle = Vector3.Angle(transform.forward, new Vector3(transform.forward.x, 0, transform.forward.z)); if (transform.forward.y < 0) { throw_angle *= -1; } action_state = p_state.aiming; } if (Input.GetMouseButtonUp(1)) { action_state = p_state.throwing; } } else { action_state = p_state.waiting; } if (action_state == p_state.aiming) { if (!throw_arc.isVisible) { throw_arc.enabled = true; } //print(player_pickup.Inventory_items[0].activeSelf); //GameObject textOBJ = held_item_.transform.GetChild(0).gameObject; //print("setting the text object inactive"); //TextMesh tm = textOBJ.GetComponent<TextMesh>(); //print("this is a text mesh i promise --> " + tm.text); //textOBJ.SetActive(false); // 1. Get the inputs! (ScrollWheel and Mouse Y) float mouse_y = Input.GetAxis("Mouse Y"); float scrollwheel = Input.GetAxis("Mouse ScrollWheel"); // 2. Use ScrollWheel to increase/decrease the power throw_power += scrollwheel * 2f; throw_power = Mathf.Clamp(throw_power, 3f, 50f); // 3. Use mouse Y to increase/decrease the throw_angle throw_angle += mouse_y; throw_angle = Mathf.Clamp(throw_angle, -45f, 90f); updateObjectFacing(held_item_, throw_angle); // 4. Display the line that will show the object's movement displayThrowArc(held_item_, throw_power); // 5. Check to see if the player wants/tries to cancel the throw } if (action_state == p_state.throwing) { // 1. Take the item out of the player's inventory // 2. Launch the item with the appropriate initial velocity and direction Vector3 launch_velocity = getThrowVelocity(held_item_, throw_power); throwItem(held_item_, launch_velocity); // 3. Remove the object from the player inventory item_index = player_pickup.Inventory_items.IndexOf(held_item_); player_pickup.removeFromInventory(held_item_); // 4. Call update on the UI //ui_wheel.updateUIAfterThrow(); // 4. Set action_state back to waiting held_item_ = null; action_state = p_state.waiting; throw_arc.enabled = false; } }