Quantcast
Viewing latest article 5
Browse Latest Browse All 16

Can someone fix this building and breaking code?

I have a building and breaking block code for this game like Minecraft that I'm making. I click and I can get stuck in blocks. Also Sometimes when I click my Player gets deleted and I can't do anything unless I exit the game. I don't know if it's the code or something Please Help. var GrassBlock : Transform; var StoneBlock : Transform; var BlockSelected : float = 1; var Range : float = 20; function Update () { if (Input.GetKeyDown(KeyCode.Q)) { BlockSelected -= 1; } if (Input.GetKeyDown(KeyCode.E)) { BlockSelected += 1; } if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { var Hit : RaycastHit; var LookingDirection = transform.TransformDirection(Vector3.forward); if (Physics.Raycast(transform.position,LookingDirection, Hit, 20)) { if (Input.GetMouseButtonDown(1)) { if (BlockSelected == 1) { var GrassBlock : Transform = Instantiate(GrassBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity); GrassBlock.tag = "GrassBlock"; } if (BlockSelected == 2) { var StoneBlock : Transform = Instantiate(StoneBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity); GrassBlock.tag = "StoneBlock"; } } else { Destroy(Hit.transform.gameObject); } } } }

Viewing latest article 5
Browse Latest Browse All 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>