void Update() { if (!isDestroyed) { if (isFacingRight) { transform.position = new Vector3(transform.position.x + (shotSpeed * Time.deltaTime), transform.position.y, transform.position.z); } else { transform.position = new Vector3(transform.position.x - (shotSpeed * Time.deltaTime), transform.position.y, transform.position.z); } if (Math.Abs(lastSplatterLocation.x - transform.position.x) >= 1) { newSplatterBounceObj = Instantiate(splatterBounce, new Vector3(transform.position.x + (isFacingRight ? .5f : -.5f), transform.position.y - 1f, transform.position.z), Quaternion.identity) as SplatterBouncePaint; //newSplatterBounceObj.transform.localScale = new Vector3(.6f, .6f, .6f); lastSplatterLocation = transform.position; newSplatterBounceObj.ApplyStyle(); } Collider2D[] wallColliders = Physics2D.OverlapCircleAll(new Vector2(transform.position.x, transform.position.y), detectWallRadius); foreach (Collider2D coll in wallColliders) { if (coll.gameObject.CompareTag("PaintableSurfaceTag")) { //coll.sharedMaterial = bouncyFloorPrefab.sharedMaterial; //Debug.Log("Should have worked...."); isDestroyed = true; } } if (isDestroyed) { SplatToWall(); } } }
void SplatToWall() { SplatterBouncePaint splatterPaintToObj = (SplatterBouncePaint)Instantiate(splatterBounce, new Vector3(transform.position.x + (isFacingRight ? .5f : -.5f), transform.position.y, transform.position.z), Quaternion.identity); splatterPaintToObj.transform.localScale = new Vector3(.6f, .6f, .6f); splatterPaintToObj.ApplyStyle(); splatterBounceObj.gameObject.SetActive(false); gameObject.SetActive(false); Destroy(splatterBounceObj.gameObject.GetComponent <GameObject>()); Destroy(gameObject.GetComponent <GameObject>()); }