- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
 
- 纳金币
- 53488
- 精华
- 316
|
三个物体 一个球 一个cube 一个圆柱 点两个交换位置- using UnityEngine;
- using System.Collections;
- public class GameController : MonoBehaviour {
- public Transform first;
- void Awake() {
- first = null;
- }
- // Use this for initialization
- void Start () {
- }
-
- // Update is called once per frame
- void Update () {
- if (Input.GetMouseButtonDown(0)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- Physics.Raycast(ray, out hit);
- if (first == null) {
- first = hit.transform;
- }
- else if (first != hit.transform) {
- Vector3 temp = first.position;
- first.position = hit.transform.position;
- hit.transform.position = temp;
- first = null;
- }
- }
- }
- }
复制代码 |
|