void SpawnBlock(Vector3 pos, float health, Color col) { BlockScript b = Instantiate(blockPrefab); b.transform.position = pos; b.health = health; col.a = 1; b.GetComponent <Renderer>().material.color = col; blocks.Add(b); }
void Update() { if ((Input.GetButton("Fire1") || Input.GetButton("Fire2"))) { Vector3 rayOrigin = player.transform.position + new Vector3(0.0f, .75f, 0.0f); RaycastHit hit; laserLine.SetPosition(0, rayOrigin - new Vector3(0.25f, .75f, 0.0f)); direction = fpsCam.transform.rotation.eulerAngles; direction[0] *= 2; if (direction[0] <= -90) { direction[0] += 360; } direction = Quaternion.Euler(direction) * (new Vector3(0, 0, 1)); if (Physics.Raycast(rayOrigin, direction, out hit, weaponRange)) { laserLine.SetPosition(1, hit.point); if (hit.collider.GetComponent <BlockScript>() != null) { BlockScript block2 = hit.collider.GetComponent <BlockScript>(); if (block != null && !block.readyToEntangle) { block = null; } if (block != null && block != block2 && (block2.color + block.color) % 2 == 0) // 2nd block, not entangled yet, right color { block.entangle(block2); lastEntangled[0] = block; lastEntangled[1] = block2; block.readyToEntangle = false; block = null; } else if (lastEntangled[0] == null || lastEntangled[1] == null || (lastEntangled[0] != block2 && lastEntangled[1] != block2) || lastEntangled[0].entangled == null || lastEntangled[1].entangled == null)// first block, not entangled yet { if (lastEntangled[0] != null) { lastEntangled[0].entangle(null); lastEntangled[1].entangle(null); } block = block2; Texture c = block.color == 1 ? block.red2 : block.color == 0 ? block.purple2 : block.blue2; block.GetComponent <Renderer>().material.SetTexture("_EmissionMap", c); block.readyToEntangle = true; } } } else { laserLine.SetPosition(1, rayOrigin + (direction * weaponRange)); } laserLine.enabled = true; } else { laserLine.enabled = false; } if (Input.GetKeyDown(KeyCode.Return)) { block = null; lastEntangled[0] = null; lastEntangled[1] = null; } }
private void OnTriggerStay(Collider col) { // Red gate if (col.tag == "redgate" && color == -1) { Kill(); } else if (col.tag == "redgate" && color == 0) { if (entangled != null) { if (priority + bias < entangled.priority + entangled.bias) { redGate = true; } entangled.color = redGate ? -1 : 1; entangled.GetComponent <Renderer>().material.SetTexture("_EmissionMap", redGate ? blue : red); } if (redGate) { color = 1; GetComponent <Renderer>().material.SetTexture("_EmissionMap", red); redGate = false; priority++; } else { if (entangled != null) { entangled.priority++; } Kill(); } } // Blue gate else if (col.tag == "bluegate" && color == 1) { Kill(); } else if (col.tag == "bluegate" && color == 0) { if (entangled != null) { if (priority - bias < entangled.priority - entangled.bias) { blueGate = true; } entangled.color = blueGate ? 1 : -1; entangled.GetComponent <Renderer>().material.SetTexture("_EmissionMap", blueGate?red:blue); } if (blueGate) { color = -1; GetComponent <Renderer>().material.SetTexture("_EmissionMap", blue); blueGate = false; priority++; } else { if (entangled != null) { entangled.priority++; } Kill(); } } // Purple gate else if (col.tag == "purplegate" && color != 0) { if (entangled != null) { if (priority < entangled.priority) { purpleGate = true; } if (purpleGate) { entangled.purpleGate = false; // Technically should turn green... } else { entangled.color = 0; entangled.GetComponent <Renderer>().material.SetTexture("_EmissionMap", purple); } } if (purpleGate) { color = 0; GetComponent <Renderer>().material.SetTexture("_EmissionMap", purple); purpleGate = false; } else { if (entangled != null) { entangled.priority++; } Kill(); } } // Goals else if (col.tag == "redgoal") { if (color == 1) { Kill(); levelup.red--; } else { return; // no effect } } else if (col.tag == "bluegoal") { if (color == -1) { Kill(); levelup.blue--; } else { return; // no effect } } else if (col.tag == "purplegoal") { if (color == 0) { Kill(); levelup.purple--; } else { return; // no effect } } // Barrier else if (col.tag == "barrier") { Kill(); } // Portals if (col.tag == "redportal" || col.tag == "blueportal" || col.tag == "purpleportal") { return; } readyToEntangle = false; entangle(null); }