// Update is called once per frame void Update() { Vector2 oldPos = this.transform.position; oldPos = oldPos + velocity * Time.deltaTime; this.transform.position = new Vector3(oldPos.x, oldPos.y, this.transform.position.z); if (!returning) { if (dragging || (Input.GetMouseButtonDown(0) && mouseIsOver)) { // Drag item with mouse button velocity = Vector2.zero; dragging = true; Vector3 mousePos = Input.mousePosition; mousePos.z = this.transform.position.z; mousePos = Camera.main.ScreenToWorldPoint(mousePos); mousePos.z = this.transform.position.z; this.transform.position = mousePos; duration += Time.deltaTime; // if this is the start, record position if (Input.GetMouseButtonDown(0)) { mousePosStart = new Vector2(mousePos.x, mousePos.y); } } if (dragging && Input.GetMouseButtonUp(0)) { dragging = false; Vector3 mousePos = Input.mousePosition; mousePos.z = this.transform.position.z; mousePos = Camera.main.ScreenToWorldPoint(mousePos); mousePosEnd = new Vector2(mousePos.x, mousePos.y); velocity = (mousePosEnd - mousePosStart) / duration; duration = 0; } } if (returning) { if ((this.transform.position - home).magnitude < 0.05) { this.transform.position = home; velocity = Vector2.zero; returning = false; timesThrown += 1; PetButton b = this.GetComponent <PetButton>(); if (b != null) { // Reset timer for text if player threw a button b.timeClicked = 0; } } } }
// Use this for initialization void Start () { textComponent = textbox.GetComponent<TextBox>(); textComponent.setText("Play fetch with me!"); pbar = bar.GetComponent<PetBar>(); pbutton = button.GetComponent<PetButton>(); buttonThrower = button.GetComponent<Throwable>(); animator = dog.GetComponent<Animator> (); }
// Use this for initialization void Start() { textComponent = textbox.GetComponent <TextBox>(); textComponent.setText("Play fetch with me!"); pbar = bar.GetComponent <PetBar>(); pbutton = button.GetComponent <PetButton>(); buttonThrower = button.GetComponent <Throwable>(); animator = dog.GetComponent <Animator> (); }