android - How to make my gameobject collide with walls? -
so im using code move around object, dont know how make collide walls. no matter gameobject goes through walls or if hits them bounce. sorry if simple new.
using system.collections; using system.collections.generic; using unityengine; using unityengine.ui; public class controller : monobehaviour { private float dist; private bool dragging = false; private vector3 offset; private transform todrag; public text score; public int counterofbeers; public touch touch; public bool lampa=false; void awake(){ counterofbeers = 0; } void update() { score.text= counterofbeers.tostring (); vector3 v3; if (input.touchcount != 1) { dragging = false; return; } touch = input.touches[0]; vector3 pos = touch.position; if(touch.phase == touchphase.began) { raycasthit hit; ray ray = camera.main.screenpointtoray(pos); if(physics.raycast(ray, out hit) && (hit.collider.tag == "draggable")) { debug.log ("here"); todrag = hit.transform; dist = hit.transform.position.z - camera.main.transform.position.z; v3 = new vector3(pos.x,dist); v3 = camera.main.screentoworldpoint(v3); offset = todrag.position - v3; dragging = true; } } if (dragging && touch.phase == touchphase.moved) { v3 = new vector3(input.mouseposition.x,dist); v3 = camera.main.screentoworldpoint(v3); todrag.position = v3 + offset; } if (dragging && (touch.phase == touchphase.ended || touch.phase == touchphase.canceled)) { dragging = false; } } void ontriggerenter(collider other) { if (other.gameobject.comparetag ("pickup")) { destroy (other.gameobject); counterofbeers++; } if(other.gameobject.comparetag("wall")){ lampa=true; } } }
Comments
Post a Comment