Hallo Ich folgte einem Tutorial, wie man ein Sprite durch Ziehen bewegt, aber ich kann es nicht zum Laufen bringen.Sprite mit Mausklick bewegen
Ich bin neu in der Einheit so leid, wenn dies ist ein bisschen einfach
dies das Skript an meine Hauptkamera, ich habe eine Kapsel colllider meine Sprite angebracht
danken Sie für Ihre Hilfe in erweitern
der nächste Schritt ist eine Berührungseingabe
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragMove : MonoBehaviour {
public GameObject gameObjectToDrag; // refer to Go that being dragged
public Vector3 Gocenter; // gameobject centre
public Vector3 touchPosition; // touch or click position
public Vector3 offSet; // vector between touchpoint/mouse click to the object centre
public Vector3 newGOCenter; // new center of object
RaycastHit hit; // store hit object information
public bool draggingmode = false; //
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
//********************************
// **Click to Drag****************
//********************************
// first frame when user click left button
if (Input.GetMouseButtonDown(0))
{
// convert mouse position to ray
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// if ray hit a collider (not 2dcollider)
if (Physics.Raycast(ray, out hit))
{
gameObjectToDrag = hit.collider.gameObject;
Gocenter = gameObjectToDrag.transform.position;
touchPosition = Camera.main.ScreenToWorldPoint
(Input.mousePosition);
offSet = touchPosition - Gocenter;
draggingmode = true;
}
}
// every frame when user hold left mouse
if (Input.GetMouseButtonDown(0))
{
if (draggingmode)
{
touchPosition = Camera.main.ScreenToWorldPoint
(Input.mousePosition);
newGOCenter = touchPosition - offSet;
gameObjectToDrag.transform.position = new Vector3(newGOCenter.x,
newGOCenter.y, newGOCenter.z);
}
}
if (Input.GetMouseButtonUp(0))
{
draggingmode = false;
}
}
}
ich das trotz klicken, aber nicht –
bewegt Sind Sie sicher, dass dies ein Sprite? Bitte posten "Inspektor" Registerkarte Screenshot dieses Objekts – Programmer