// Use this for initialization void Start() { target = GetComponent <Rollable>(); target.SetProps(controllerProps); }
void DetectGroundBlock() { tileBounds.size = new Vector3(1, 1, 1); tileBounds.center = new Vector3( (int)((transform.position.x + (transform.position.x >= 0 ? 0.5f : -0.5f)) / 1.0f) * 1.0f, (int)((transform.position.y + (transform.position.y >= 0 ? 0.5f : -0.5f)) / 1.0f) * 1.0f, (int)((transform.position.z + (transform.position.z >= 0 ? 0.5f: -0.5f)) / 1.0f) * 1.0f); Ray ray = new Ray(transform.position, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, character.height * 0.75f)) { BoxCollider collider = hit.collider.GetComponent <BoxCollider>(); if (collider == null) { blockBounds = null; availableMovementBounds.Clear(); } else { Bounds b = collider.bounds; // check if the bounds are different... if so, update if (b != blockBounds) { blockBounds = b; availableMovementBounds.Clear(); availableMovementBounds.Add(b); if (IsBlockInPosition(b.center + Vector3.left)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.left, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.right)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.right, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.forward)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.forward, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.back)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.back, Vector3.one)); } if (rollable) { rollable.diceMesh.transform.localScale = Vector3.one; rollable.SetEmissiveness(0.0f); } rollable = hit.collider.GetComponent <Rollable>(); if (rollable) { rollable.diceMesh.transform.localScale -= new Vector3(0.1f, 0.1f, 0.1f); rollable.SetEmissiveness(0.4f); rollable.SetProps(props); } } } } if (rollable) { Bounds b = rollable.GetComponent <BoxCollider>().bounds; availableMovementBounds.Clear(); availableMovementBounds.Add(b); if (rollable.IsRolling() == false) { if (IsBlockInPosition(b.center + Vector3.left)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.left, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.right)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.right, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.forward)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.forward, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.back)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.back, Vector3.one)); } } } }