Android 如何使我的游戏对象与墙壁碰撞?

Android 如何使我的游戏对象与墙壁碰撞?,android,touch,Android,Touch,所以我用这个代码在一个物体周围移动,但我不知道如何使它和墙壁碰撞。无论我做什么,游戏物体都会穿过墙壁,或者如果它碰到墙壁,它们就会反弹。对不起,如果太简单了,我是新来的 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class controller : MonoBehaviour {

所以我用这个代码在一个物体周围移动,但我不知道如何使它和墙壁碰撞。无论我做什么,游戏物体都会穿过墙壁,或者如果它碰到墙壁,它们就会反弹。对不起,如果太简单了,我是新来的

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;
             }
         }
     }

你在墙上应用过碰撞器吗?是的,盒子碰撞器。有没有办法让我的游戏对象从墙上反弹?