void checkForGrabbing() { if (Input.GetMouseButtonDown(0) && !holding) { pickup = findPickUp(); if (pickup != null) { pickUpScript = pickup.GetComponent <pickUpBehavior> (); if (pickUpScript.houseIsAvailable()) { Debug.Log("pickup"); Debug.Log("mousPos: " + mousePos + " " + "hitPos: " + pickup.transform.position); Debug.Log("distance btwn mouse and pickup: " + Vector2.Distance(mousePos, pickup.transform.position)); // Debug.Break (); p1.Play(); setToMousePos(pickup); pickUpScript.heldByMouse = true; holding = true; } else { Debug.Log("cannot pick up, house is not activated yet or you just missed..."); if (pickUpScript != null) { Debug.Log("houseavailable: " + pickUpScript.houseIsAvailable()); } else { Debug.Log("picupScript is null"); } pickup = null; pickUpScript = null; holding = false; } } else { pickup = null; pickUpScript = null; holding = false; } } if (Input.GetMouseButton(0)) { if (holding) { setToMousePos(pickup); pickUpScript.heldByMouse = true; } } else { release(); } }
// Use this for initialization void Start () { holding = false; mousePos = Vector3.zero; Cursor.lockState = CursorLockMode.Confined; Cursor.visible = false; pickup = null; pickUpScript = null; AudioSource[] A = grabber.GetComponents<AudioSource>(); p1 = A[0]; p2 = A[1]; }
// Use this for initialization void Start() { holding = false; mousePos = Vector3.zero; Cursor.lockState = CursorLockMode.Confined; Cursor.visible = false; pickup = null; pickUpScript = null; AudioSource[] A = grabber.GetComponents <AudioSource>(); p1 = A[0]; p2 = A[1]; }
void release() { if (holding) { //call pickup.release function that checks for any bins nearby and snap to nearest one, otherwise //go back to original position p2.Play(); pickUpBehavior pickUpScript = pickup.GetComponent <pickUpBehavior>(); pickUpScript.released(mousePos); holding = false; pickup = null; Debug.Log("holding == false"); } }
// Use this for initialization void Awake () { props = GetComponentInParent<pickUpBehavior>(); myRend = gameObject.GetComponent<SpriteRenderer>(); for (int i = 0; i < props.attrs.Length; i++) { if (props.attrs[i] == prop) { myRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); break; } else { Debug.Log(prop); myRend.color = new Color(1.0f, 1.0f, 1.0f, 0.0f); } } }
// Use this for initialization void Awake() { props = GetComponentInParent <pickUpBehavior>(); myRend = gameObject.GetComponent <SpriteRenderer>(); for (int i = 0; i < props.attrs.Length; i++) { if (props.attrs[i] == prop) { myRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); break; } else { Debug.Log(prop); myRend.color = new Color(1.0f, 1.0f, 1.0f, 0.0f); } } }
void checkForGrabbing(){ if (Input.GetMouseButtonDown(0) && !holding) { pickup = findPickUp(); if (pickup != null){ pickUpScript = pickup.GetComponent<pickUpBehavior> (); if (pickUpScript.houseIsAvailable ()) { Debug.Log ("pickup"); Debug.Log ("mousPos: " + mousePos + " " + "hitPos: " + pickup.transform.position); Debug.Log ("distance btwn mouse and pickup: " + Vector2.Distance (mousePos, pickup.transform.position)); // Debug.Break (); p1.Play(); setToMousePos (pickup); pickUpScript.heldByMouse = true; holding = true; } else { Debug.Log ("cannot pick up, house is not activated yet or you just missed..."); if (pickUpScript != null) { Debug.Log ("houseavailable: " + pickUpScript.houseIsAvailable ()); } else { Debug.Log ("picupScript is null"); } pickup = null; pickUpScript = null; holding = false; } } else { pickup = null; pickUpScript = null; holding = false; } } if (Input.GetMouseButton (0)) { if (holding) { setToMousePos (pickup); pickUpScript.heldByMouse = true; } } else { release (); } }