public GameObject GetCubeAtIndex(int col, int row) { if (col >= cubeSpread) { col = col % cubeSpread; } if (col < 0) { col = cubeSpread + col; } GameObject cube = cubeRow[col]; while (cube != null && row > 0) { CubeScript cs = cube.GetComponent <CubeScript>(); if (cs != null) { cube = cs.GetCubeAbove(); row -= 1; } else { return(null); } } return(cube); }
public List <GameObject> FindMatchingCubes(GameObject cube) { CubeScript cubeScript = cube.GetComponent <CubeScript>(); HashSet <GameObject> matchingCubes = new HashSet <GameObject>(); List <GameObject> candidateCubes = new List <GameObject>(); matchingCubes.Add(cube); AddRangeNonNull(candidateCubes, matchingCubes, cubeScript); while (candidateCubes.Count > 0) { GameObject nextCubeGO = candidateCubes[0]; candidateCubes.RemoveAt(0); CubeScript nextCube = nextCubeGO.GetComponent <CubeScript>(); if (nextCube.type == cubeScript.type) { matchingCubes.Add(nextCubeGO); AddRangeNonNull(candidateCubes, matchingCubes, nextCube); } } var arr = new GameObject[matchingCubes.Count]; matchingCubes.CopyTo(arr); return(new List <GameObject>(arr)); }
public void Awake() { if (instance == null) { instance = this; } }
void OnTriggerEnter(Collider collision) { //if the cube unlocker hits a TNT charge, explode it after a short delay if (collision.gameObject.tag.Equals("TNT")) { StartCoroutine(collision.gameObject.GetComponent <TNTscript>().explode()); } //if the object is not the ground (tag "Immobile") and the CubeUnlocker hasn't already tried unlocking in a previous frame else if (collision.gameObject.GetComponent <Rigidbody>() == null && !collision.gameObject.tag.Equals("Immobile")) { Rigidbody rb = collision.gameObject.AddComponent <Rigidbody>(); //doesnt work //rb.AddExplosionForce(100, collision.gameObject.transform.position, 10, 10.0f); int randXforce = Random.Range(-7, 7); int randYforce = Random.Range(1, 5); int randZforce = Random.Range(-7, 7); rb.AddForce(randXforce, randYforce, randZforce, ForceMode.Impulse); ScoreManager.GetComponent <ScoreScript>().tallyCube(); CubeScript cs = collision.gameObject.GetComponent <CubeScript>(); if (cs != null) { cs.isActive = true; } } }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hitInfo = new RaycastHit(); Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo); CubeScript cubeScript = hitInfo.transform.gameObject.GetComponent <CubeScript>(); // // if (cubeScript.hitDirection.Equals (moveDirection)) { // pointB = hitInfo.transform.position; // pointB.y= transform.position.y; // transform.parent = hitInfo.transform; // } } if (!pointA.Equals(pointB)) { transform.position = Vector3.MoveTowards(transform.position, pointB, 0.1f); } else { pointA = transform.position; } }
public void CheckColor() { colorcheck++; float numerocolore; int numeromatch = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { CubeScript cubocorrente = cubearray[i, j].GetComponentInChildren <CubeScript>(); numerocolore = cubocorrente.numerocol; if (cubocorrente.indey > 0) { if (numerocolore == cubearray[cubocorrente.index, cubocorrente.indey - 1].GetComponentInChildren <CubeScript>().numerocol) { cubocorrente.isIncontact = true; numeromatch++; } } ; if (cubocorrente.index > 0) { if (numerocolore == cubearray[cubocorrente.index - 1, cubocorrente.indey].GetComponentInChildren <CubeScript>().numerocol) { cubocorrente.isIncontact = true; numeromatch++; } } ; if (cubocorrente.index < 7) { if (numerocolore == cubearray[cubocorrente.index + 1, cubocorrente.indey].GetComponentInChildren <CubeScript>().numerocol) { cubocorrente.isIncontact = true; numeromatch++; } } ; if (cubocorrente.indey < 7) { if (numerocolore == cubearray[cubocorrente.index, cubocorrente.indey + 1].GetComponentInChildren <CubeScript>().numerocol) { cubocorrente.isIncontact = true; numeromatch++; } } ; } ; } if (numeromatch < 1) { OnEndGame(); } }
void Update() { if (gen.initialized) { if (Input.GetKeyDown(KeyCode.Space)) { HandleCreateKeyPress(); } if (iCube != null) { FollowMouse(); if (Input.GetKeyDown(KeyCode.X)) { HandleChangeTextureKeyPress(); } if (Input.GetMouseButtonDown(0)) { CubeScript cube = iCube.GetComponentInChildren <CubeScript>(); if (cube.collisions == 0 && cube.canBePlaced) { iCube.GetChild(0).gameObject.layer = LayerMask.NameToLayer("Default"); Cubes.Add(iCube); iCube = null; } } } } }
public void SelectTile(CubeScript tile) { if (!_isMyTurnToMove) { return; } //gameCamera.StopAllCoroutines(); if (selectedTile != tile) { selectedTile = tile; buttonDeselect.SetActive(true); gameFieldUI.UpdateMineButton(true); tileSelectBox.SetPosition(selectedTile.transform.position.x, selectedTile.transform.position.z); tileSelectBox.SetVisibility(true); //var currZoom = gameCamera.GetCurrentZoom(); //if (currZoom > 50) //{ // gameCamera.CameraMoveToTile(selectedTile.transform.position.x, selectedTile.transform.position.z); // gameCamera.CameraChangeZoom(50); //} } else { StartCoroutine(ApiService.SetPointAsync(x => { }, currentGameId, (int)tile.tileCoords.x, (int)tile.tileCoords.y)); DeselectTile(); } }
public Composite SpawnCube( Vector2 pos, float angle, float relativeForce, float burstDuration, float burstDelay, Color color) { Composite comp = CompositePool.Instance.ForceCreateComposite(); if (comp != null) { CubeScript spawned = null; float rand = Random.value; if (rand < cubeProb) { spawned = SpawnCube(relativeForce, burstDuration, burstDelay, color); } else if (rand < cubeProb + 0.0f) { //TODO: add probability based spawning } //center random position spawned.transform.position = transform.TransformPoint(new Vector3(pos.x, pos.y, 0.0f)) + 0.5f * Vector3.one; spawned.transform.rotation *= Quaternion.AngleAxis(angle, Vector3.up); spawned.transform.parent = comp.transform; comp.Color = spawned.Color; comp.HP = 1; comp.AbsorbRigidbody(spawned.GetComponent <Rigidbody>()); Destroy(spawned.GetComponent <Rigidbody>()); comp.CreateTarget(); } return(comp); }
private CubeScript GetTile(Vector2 coords) { CubeScript tile = null; dictTiles.TryGetValue(coords, out tile); return(tile); }
void Start() { cubeScript = gameObject.GetComponent <CubeScript> (); WebCamDevice[] devices = WebCamTexture.devices; webcamTexture = new WebCamTexture(devices[0].name, Width, Height, FPS); webcamTexture.Play(); }
public void CaseSelected(CubeScript cS) { ClearZone(); target = cS; CastSpell(currentSpell); }
//MenuCommand是系统传入的在哪个组件上右击 static void ModifySpeed(MenuCommand cmd) { //返回cube游戏对象的CubeScript组件 CubeScript cubeSc = cmd.context as CubeScript; Debug.Log(cubeSc); cubeSc.Speed = 3.0f; }
void Start() { //Reguest.GET can be called passing in your ODATA url as a string in the form: //http://{Your Site Name}.azurewebsites.net/tables/{Your Table Name}?zumo-api-version=2.0.0 //The response produce is a JSON string string jsonResponse = Request.GET(_WebsiteURL); //Just in case something went wrong with the request we check the reponse and exit if there is no response. if (string.IsNullOrEmpty(jsonResponse)) { return; } //We can now deserialize into an array of objects - in this case the class we created. The deserializer is smart enough to instantiate all the classes and populate the variables based on column name. Mountain[] mountains = JsonReader.Deserialize <Mountain[]>(jsonResponse); //---------------------- //YOU WILL NEED TO DECLARE SOME VARIABLES HERE SIMILAR TO THE CREATIVE CODING TUTORIAL int i = 0; int totalCubes = mountains.Length; float totalDistance = 2.9f; //---------------------- //We can now loop through the array of objects and access each object individually foreach (Mountain mt in mountains) { //Example of how to use the object Debug.Log("This products name is: " + mt.MountainName); //---------------------- //YOUR CODE TO INSTANTIATE NEW PREFABS GOES HERE //float perc = i / (float)totalCubes; //float sin = Mathf.Sin(perc * Mathf.PI / 2); // float x = mt.X; float y = mt.Y; float z = mt.Z; var newCube = Instantiate(myPrefab, new Vector3(x, y, z), Quaternion.identity); CubeScript cubeScript = newCube.GetComponent <CubeScript>(); cubeScript.mountain = mt; // Use the mountains size to set the scale. cubeScript.SetSize(mt.Size); // if (mt.Symbol == "Sphere") { newCube.GetComponent <MeshFilter>().mesh = cubeScript.sphereMesh; } newCube.transform.Find("New Text").GetComponent <TextMesh>().text = mt.MountainName;//"Hullo Again"; i++; //---------------------- } }
public void AttachToCube(PlayerScript p, Vector3 axis, float cSize, GameObject cube) { cubeSize = cSize; bombAxis = axis; player = p; strength = player.bombStrength; target = cube.GetComponent <CubeScript>(); currentTime = 0; }
public void SetAboveDestroyable() { if (adjacencies[2] != null) { CubeScript cubeScript = adjacencies[2].GetComponent <CubeScript>(); cubeScript.destroyable = true; cubeScript.SetAboveDestroyable(); } }
public MineScript InsertMine(CubeScript tile, string playerId) { var obj = Instantiate(minePrefab); obj.name = "mine " + tile.tileCoords; obj.SetMineTile(tile, playerId == currentPlayerId); return(obj); }
public void DeselectTile() { //gameCamera.StopAllCoroutines(); //gameCamera.CameraChangeZoom(75); selectedTile = null; buttonDeselect.SetActive(false); tileSelectBox.SetVisibility(false); gameFieldUI.UpdateMineButton(false); }
void Start() { CubeScript cubeScript = new CubeScript(); food = cubeScript.CreateCube(shader, foodColor); food.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); food.transform.parent = gameObject.transform; food.AddComponent <FoodTriggerScript>(); }
/// <summary> /// Set mined tile /// </summary> /// <param name="tile">Tile</param> /// <param name="isVisible">Is mine visible for the player</param> /// <param name="setPosition">Set the same position of the mine as tile</param> public void SetMineTile(CubeScript tile, bool isVisible, bool setPosition = true) { _mineObject.SetActive(isVisible); _minedTile = tile.gameObject; if (setPosition) { transform.position = _minedTile.transform.position; } }
public int[] GetMinMaxValues(GameObject[] inputCubes) { // The default output if there is only 1 cube (max is 1 cube in all directions). // The format of the output array is // {minX, maxX, minY, maxY, minZ, maxZ} int[] output = new int[] { 0, 0, 0, 0, 0, 0 }; foreach (GameObject cube in inputCubes) { // Compare the x, y, and z coordinate stored in each cube // to the default values. If greater than a max or less than a min, update the output. CubeScript tempScript = cube.GetComponent <CubeScript>(); // If we are able to get a CubeScript from the puzzle, proceed. // Do this to avoid picking up some random object imporperly assigned a BuildCube tag. if (tempScript != null) { // Test the minimum/maximum X value int testValue = tempScript.GetPuzzleUnit().xIndex; if (testValue < output[0]) { output[0] = testValue; } if (testValue > output[1]) { output[1] = testValue; } // Test the minimum/maximum Y value testValue = tempScript.GetPuzzleUnit().yIndex; if (testValue < output[2]) { output[2] = testValue; } if (testValue > output[3]) { output[3] = testValue; } // Test the minimum/maximum Z value testValue = tempScript.GetPuzzleUnit().zIndex; if (testValue < output[4]) { output[4] = testValue; } if (testValue > output[5]) { output[5] = testValue; } } }// end of foreach return(output); }
public void PropagateRowIndex() { if (adjacencies[2] == null) { return; } CubeScript cs = adjacencies[2].GetComponent <CubeScript>(); cs.SetCubeRowIndex(cubeRowIndex + 1); cs.SetLeftRightAdjacencies(); cs.PropagateRowIndex(); }
private void OnTriggerExit(Collider other) { if (other.CompareTag("Cube")) { if (this.cubes.Contains(other.gameObject)) { CubeScript cs = other.gameObject.GetComponent <CubeScript>(); cs.canFlash = false; this.cubes.Remove(other.gameObject); } } }
private CubeScript SpawnCube() { GameObject spawned = Instantiate(cubePrefab); CubeScript cube = spawned.GetComponent <CubeScript>(); cube.RelativeForce = new Vector3(0.0f, 0.0f, Random.Range(RelativeForceRange[MIN], RelativeForceRange[MAX])); cube.BurstDuration = Random.Range(BurstDurationRange[MIN], BurstDurationRange[MAX]); cube.BurstDelay = Random.Range(BurstRateRange[MIN], BurstRateRange[MAX]); cube.Color = colors[Random.Range(0, colors.Length)]; return(cube); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { renderer.material = materials[0]; } if (Input.GetKeyDown(KeyCode.Alpha2)) { renderer.material = materials[1]; } if (Input.GetKeyDown(KeyCode.Alpha3)) { renderer.material = materials[2]; } if (Input.GetKeyDown(KeyCode.Alpha4)) { renderer.material = materials[3]; } if (Input.GetKeyDown(KeyCode.Alpha5)) { renderer.material = materials[4]; } if (Input.GetKeyDown(KeyCode.Alpha6)) { renderer.material = materials[5]; } if (Input.GetKeyDown(KeyCode.DownArrow)) { CubeScript cubeScript = GetComponent <CubeScript>(); cubeScript.speed -= 1; } if (Input.GetKeyDown(KeyCode.UpArrow)) { CubeScript cubeScript = GetComponent <CubeScript>(); cubeScript.speed += 1; } if (Input.GetKeyDown(KeyCode.Space)) { Camera cam = Camera.main; if (cam.orthographic) { cam.orthographic = false; } else { cam.orthographic = true; } } }
void OnCollisionEnter(Collision collision) { //if a cube hits the ground if (collision.gameObject.tag.Equals("Cube")) { //check if the cube has already been scored, also avoid cubes that haven'g been activated by a bomb (the ones that spawn at ground level) CubeScript cubeScript = collision.gameObject.GetComponent <CubeScript>(); if (!cubeScript.pointTallied && cubeScript.isActive) { cubeScript.pointTallied = true; cubeScript.isActive = false; ScoreManager.GetComponent <ScoreScript>().tallyCube(); } } }
private CubeScript SpawnCube(float relativeForce, float burstDuration, float burstDelay, Color color) { GameObject spawned = Instantiate(cubePrefab); CubeScript cube = spawned.GetComponent <CubeScript>(); cube.RelativeForce = new Vector3(0.0f, 0.0f, relativeForce); cube.BurstDuration = burstDuration; cube.BurstDelay = burstDelay; cube.PreventSticky = false; cube.Color = color; return(cube); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Cube")) { Debug.Log("cube entered"); this.cubes.Add(other.gameObject); if (transform.parent.gameObject.tag == "Player") { CubeScript cs = other.gameObject.GetComponent <CubeScript>(); cs.flashRoutine = cs.FlashCubeTimer(); cs.canFlash = true; StartCoroutine(cs.flashRoutine); } } }
void Start() { body = new List <GameObject>(); cubeScript = new CubeScript(); Vector3 endPos = new Vector3(3.5f, 0.5f, 19f); GameObject cube; currentColor = color1; int i, j, k; for (i = 0; i < initialSnakeLength; i++) { cube = CreateCubeAt(endPos, currentColor); AlternateCurrentColor(); cube.transform.Translate(Vector3.right * i); body.Add(cube); if (i >= 20) { break; } } k = 0; for (j = i + 1; j < initialSnakeLength; j++) { cube = CreateCubeAt(endPos, currentColor); AlternateCurrentColor(); cube.transform.Translate(new Vector3(i, 0, -k)); body.Add(cube); k++; } body[0].AddComponent <CollisionScript>(); body[0].tag = "SnakeHead"; body[1].tag = "NextToSnakeHead"; direction = Vector3.forward; nextStepDirection = direction; cubesToAdd = 0; collided = false; UpdateShading(); }
public int FindCubeIndex(GameObject target) { GameObject cube = cubeRow[target.GetComponent <CubeScript>().GetCubeIndex()]; int counter = 0; while (cube != null && cube != target) { CubeScript cubeScript = gameObject.GetComponent <CubeScript>(); if (cubeScript == null) { break; } cube = cubeScript.GetCubeAbove(); counter++; } return(counter); }
public static CubeScript Instance() { if(!_instance) { CubeScript[] objs = (CubeScript[])GameObject.FindObjectsOfType(typeof(CubeScript)); if(objs.Length > 1) { foreach(CubeScript obj in objs) { GameObject.DestroyObject(obj); } } _instance = (CubeScript)GameObject.FindObjectOfType(typeof(CubeScript)); } if(!_instance) { GameObject obj = new GameObject("CubeScript"); _instance = obj.AddComponent(typeof(CubeScript)) as CubeScript; } return _instance; }
IEnumerator parseIdentify(WWW www, string personIdMatch, float myX, float myY) { yield return(www); if (www.error == null) { Debug.Log("WWW2 : " + www.data); string myJson = www.data.ToString(); JSONObject j1 = new JSONObject(myJson); times = 0; myPersonID = ""; try{ accessDataPerson(j1); } finally { } Debug.Log("past ACCESSDATAPERSON"); Debug.Log("personID: " + myPersonID); //parse www.data.candidates[0].personId; //get real personId if (myPersonID == personIdMatch) { // CubeScript2 cubescript2 = FindObjectOfType<CubeScript2> (); // cubescript2.updateCubePosition (myX, myY); Debug.Log("MATCH!"); CubeScript cubescript = FindObjectOfType <CubeScript> (); cubescript.updateCubePosition(myX, myY); } else { // CubeScript cubescript = FindObjectOfType<CubeScript> (); // cubescript.updateCubePosition (myX, myY); Debug.Log("Not matched :("); CubeScript2 cubescript2 = FindObjectOfType <CubeScript2> (); cubescript2.updateCubePosition(myX, myY); } } else { Debug.Log("WWW Error: " + www.error); } }
public void UpdatePosition() { Vector3 behind = -transform.TransformDirection(Vector3.up); RaycastHit hit; if (Physics.Raycast(transform.position, behind, out hit)) { actualPosition = new Vector2(hit.transform.position.x, hit.transform.position.z); hit.transform.GetComponent<CubeScript>().occupant = this; if (previousTile) { previousTile.occupant = null; } previousTile = hit.transform.GetComponent<CubeScript>(); } }
public void ResetSpell() { target = null; dropdown.value = 0; ClearZone(); dropdownObject.SetActive(false); }
void Start() { bodyMovement = GetComponent<CubeScript> (); }
// Update is called once per frame void Update() { if (gameOver == true) { if (playerturn == 1) victoryRedText.enabled = true; else victoryBlueText.enabled = true; } if (gameOver == false) { if (Input.GetMouseButtonUp(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out rch, 100)) { mRend = rch.transform.gameObject.GetComponent<MeshRenderer>(); clickParticles.Stop(); if (mRend.material.name.Equals("TicTacTurnBlankUVMap (Instance)")) { if (playerturn == 1) { tempmats = mRend.materials; tempmats.SetValue(x_mat, 0); tempmats.SetValue(x_mat, 1); tempmats.SetValue(x_mat, 2); tempmats.SetValue(x_mat, 3); mRend.materials = tempmats; cubeScript = rch.transform.gameObject.GetComponent<CubeScript>(); clickParticles.transform.position = rch.transform.gameObject.transform.position; clickParticles.Play(); cubeScript.value = 1; playerturn = 2; } else if (playerturn == 2) { tempmats = mRend.materials; tempmats.SetValue(o_mat, 0); tempmats.SetValue(o_mat, 1); tempmats.SetValue(o_mat, 2); tempmats.SetValue(o_mat, 3); mRend.materials = tempmats; cubeScript = rch.transform.gameObject.GetComponent<CubeScript>(); clickParticles.transform.position = rch.transform.gameObject.transform.position; clickParticles.Play(); cubeScript.value = 2; playerturn = 1; } } } } } if (Input.GetKeyDown(KeyCode.LeftArrow) && state.Equals("stand")) state = "left"; else if (Input.GetKeyDown(KeyCode.RightArrow) && state.Equals("stand")) state = "right"; else if (Input.GetKeyDown(KeyCode.UpArrow) && state.Equals("stand")) state = "up"; else if (Input.GetKeyDown(KeyCode.DownArrow) && state.Equals("stand")) state = "down"; }