void DropObject() { Debug.Log("DROP!!!"); hasDropt = true; dropObj = Instantiate(drop); dropObj.transform.position = transform.position; //for size animation dropObj.transform.localScale = Vector2.one * 0.5f; //WIP TODO: ITEM etc quick fix HumanMagnet magnet = dropObj.GetComponent <HumanMagnet>(); magnet.enabled = false; //target pos for drop dropTarget = new Vector2(transform.position.x, transform.position.y - dropTravelDis); //start drop movement StartCoroutine(MoveDropObject(dropObj, dropTarget, dropSpeed)); }
public IEnumerator MoveDropObject(GameObject drop, Vector2 posTo, float speed) { float elapsedTime = 0; Vector3 startingScale = drop.transform.localScale; Vector3 startPos = drop.transform.position; Vector2 scaleTo = Vector2.one; while (elapsedTime < speed) { drop.transform.localScale = Vector3.Lerp(startingScale, scaleTo, (elapsedTime / speed)); drop.transform.position = Vector3.Lerp(startPos, posTo, (elapsedTime / speed)); elapsedTime += Time.deltaTime; yield return(new WaitForEndOfFrame()); } drop.transform.localScale = scaleTo; drop.transform.position = posTo; //WIP TODO: ITEM etc quick fix HumanMagnet magnet = dropObj.GetComponent <HumanMagnet>(); magnet.enabled = true; SoundManager.instance.playDropSound(); }