纳金网

标题: 三个物体 一个球 一个cube 一个圆柱 点两个交换位置 [打印本页]

作者: 烟雨    时间: 2015-5-29 02:55
标题: 三个物体 一个球 一个cube 一个圆柱 点两个交换位置

三个物体 一个球 一个cube 一个圆柱 点两个交换位置
  1. using UnityEngine;
  2. using System.Collections;

  3. public class GameController : MonoBehaviour {
  4.     public Transform first;
  5.     void Awake() {
  6.         first = null;
  7.     }
  8.         // Use this for initialization
  9.         void Start () {

  10.         }
  11.        
  12.         // Update is called once per frame
  13.         void Update () {
  14.         if (Input.GetMouseButtonDown(0)) {
  15.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  16.             RaycastHit hit;
  17.             Physics.Raycast(ray, out hit);
  18.             if (first == null) {
  19.                 first = hit.transform;
  20.             }
  21.             else if (first != hit.transform) {
  22.                 Vector3 temp = first.position;
  23.                 first.position = hit.transform.position;
  24.                 hit.transform.position = temp;
  25.                 first = null;
  26.             }

  27.         }
  28.         }
  29. }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5