Euras

PlaceBlock

Feb 1st, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1.     private void Build (){
  2.         if (HitBlock ()) {
  3.             GameObject block = GameObject.CreatePrimitive (PrimitiveType.Cube);
  4.                        
  5.             block.transform.name = "Build Block";
  6.             block.transform.parent = buildBlocks.transform;
  7.             block.tag = "buildBlock";
  8.            
  9.             block.AddComponent<Highlight> ();
  10.             block.AddComponent<GlobalValues> ();
  11.             Material newMat = new Material(Shader.Find("Legacy Shaders/Self-Illumin/Bumped Diffuse"));
  12.             newMat.color = new Color32(148, 148, 148, 255);
  13.             block.GetComponent<Renderer>().material = newMat;
  14.             block.GetComponent<GlobalValues> ().i = blockType;
  15.             newMat.mainTexture = tex ();
  16.  
  17.             Vector3 cursorPosition = hit.transform.position + hit.normal;
  18.             block.transform.position = cursorPosition;
  19.             blockCount++;
  20.             lastBlocksPlaced.Add (block);
  21.         }
  22.     }
  23.  
  24.     public bool HitBlock() {
  25.         Ray posRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  26.         return Physics.Raycast(posRay, out hit, Mathf.Infinity);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment