private void StartMovement(float angle) { transform.RotateAround(transform.up, angle * Mathf.Deg2Rad); destination = transform.position + transform.forward * BuildGrid.getGridSize(); state = States.moving; nextMoveTime = Time.timeSinceLevelLoad + MOVE_DELAY + BuildGrid.getGridSize() / SPEED; }
void Start() { tileLayer = 1 << LayerMask.NameToLayer("Tile Marker"); size *= BuildGrid.getGridSize(); if (AreaClear(size)) { float halfWidth = 0.5f; //HACK: The +/- 2 here comes from the factory bounds CreatePrefab(prefab, transform.position, new Vector3(size.x - 2f, 0f, -size.z + 2f) * halfWidth); } Destroy(gameObject); }
bool AreaClear(Vector3 size) { float gridSize = BuildGrid.getGridSize(); int girdCountX = (int)Mathf.Ceil(size.x / gridSize); int girdCountZ = (int)Mathf.Ceil(size.z / gridSize); Vector3 center = transform.position; for (int x = 0; x < girdCountX; x++) { for (int z = 0; z < girdCountZ; z++) { Vector3 spherePos = center + x * gridSize * Vector3.right - z * gridSize * Vector3.forward; Collider[] overlap = Physics.OverlapSphere(spherePos, 0.01f, tileLayer); //HACK if (overlap.Length == 1 && overlap[0].tag == "Rock") { ResourceController rc = overlap[0].GetComponent <ResourceController>(); if (rc && !rc.IsSpawned()) { Destroy(overlap[0].gameObject); return(true); } return(false); } else if (overlap.Length > 0) { return(false); } } } return(true); }
void Start() { radius *= BuildGrid.getGridSize(); CreatePrefab(powerFieldPrefab, transform.position, Vector3.one * radius); }