using UnityEngine; using cakeslice; public class MoxingControl : MonoBehaviour { private…
- User
using UnityEngine; using cakeslice; public class MoxingControl : MonoBehaviour { private Transform selectedPart = null; private Outline outline = null; private Color selectedColor = Color.yellow; private bool isControlEnabled = false; private Animator animator; private bool animatorEnabled = true; public void ToggleControlEnabled() { isControlEnabled = !isControlEnabled; animator.enabled = !animator.enabled; } private void Update() { animator = GetComponent(); if (!isControlEnabled) return; if (Input.GetMouseButtonDown(0)) { Transform clickedPart = GetClickedPart(transform); if (clickedPart != null) { if (selectedPart != null) { Destroy(outline); if (selectedPart == clickedPart) { selectedPart = null; return; } } selectedPart = clickedPart; outline = selectedPart.gameObject.AddComponent(); // outline.OutlineColor = selectedColor; // outline.OutlineWidth = 4; } else if (selectedPart != null) { Destroy(outline); selectedPart = null; } } if (Input.GetMouseButton(0) && selectedPart != null) { Vector3 mousePosition = Input.mousePosition; mousePosition.z = Camera.main.WorldToScreenPoint(selectedPart.position).z; Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition); selectedPart.position = worldMousePosition; } } private Transform GetClickedPart(Transform parent) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Transform clickedPart = hit.transform; if (IsDescendant(clickedPart, parent)) { return clickedPart; } } return null; } private bool IsDescendant(Transform child, Transform parent) { foreach (Transform t in parent) { if (t == child) return true; if (IsDescendant(child, t)) return true; } return false; } }修改代码,点击零件,坐标轴显示在模型子零件上方,并且让模型进行坐标轴三个方向上的位移。
- Assistant
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.