Angenommen, das Skript, das Sie mit dem Link verknüpft haben, heißt SwipeControl
, können Sie eine öffentliche boolean
Variable namens swipedRight
hinzufügen. Jedesmal wenn der Spieler nach rechts wischt, setze es auf wahr.
Dann in Ihrem Hauptskript, wo Sie nach dieser Bedingung suchen sollen, setzen Sie es auf false
, wenn es true
ist.
In SwipeControl
:
public bool swipedRight = false;
//Check if drag distance is greater than 20% of the screen height
if (Mathf.Abs(lp.x - fp.x) > dragDistance || Mathf.Abs(lp.y - fp.y) > dragDistance)
{//It's a drag
//check if the drag is vertical or horizontal
if (Mathf.Abs(lp.x - fp.x) > Mathf.Abs(lp.y - fp.y))
{ //If the horizontal movement is greater than the vertical movement...
if ((lp.x>fp.x)) //If the movement was to the right)
{ //Right swipe
//Set Swiped Right to true
swipedRight = true;
Debug.Log("Right Swipe");
}
else
{ //Left swipe
Debug.Log("Left Swipe");
}
}
else
{ //the vertical movement is greater than the horizontal movement
if (lp.y>fp.y) //If the movement was up
{ //Up swipe
Debug.Log("Up Swipe");
}
else
{ //Down swipe
Debug.Log("Down Swipe");
}
}
}
dann von dem anderen Script:
public CharacterController cController;
Rigidbody ccRigidBody;
SwipeControl swipeControl;
void Start()
{
//Get reference to SwipeControl script
swipeControl = GameObject.Find("GameObjectSwipeControlIsAttachedTo").GetComponent<SwipeControl>();
//Get reference to the Rigidbody in the CharacterController
ccRigidBody = ccRigidBody.GetComponent<Rigidbody>();
}
void Update()
{
if (swipeControl.swipedRight && ccRigidBody.velocity==Vector3.zero)
{
//Do your stuff here
//Then set swipedRight to false
swipeControl.swipedRight = false;
}else if(swipeControl.swipedRight){
swipeControl.swipedRight = false;
}
}
Also Ihr if(**swipescript detects swipe right** && character is idle)
Code if (swipeControl.swipedRight && ccRigidBody.velocity==Vector3.zero)
in dem obigen Code übersetzt wird.
Süß. Der erste Teil des Skripts funktioniert (von dieser Website) und ich verstehe, was Sie meinen, indem swipeControl auf false gesetzt wird, nachdem es die if-Anweisung durchlaufen hat. Obwohl mein Charakter keine Starrkörperkomponente oder irgendetwas wirklich hat. Das einzige, was daran angebracht ist, ist ein Skript. Der Charakter Leerlauf ist nur eine Animator-Komponente. –
@itsPav Wenn das Zeichen Idle nur eine Animator-Komponente ist, ersetzen Sie 'ccRigidBody.velocity == Vector3.zero' durch den Idle-Code des Animators. Das sollte funktionieren. Wenn das Ihr Problem gelöst hat, können Sie weitermachen und es als Antwort akzeptieren. – Programmer
Ich habe alles, was mit rigidbody im obigen Code zusammenhängt, entfernt und durch meine animator idle-Anweisung ersetzt. Holen Sie den Objektreferenz immer noch nicht auf eine Instanz eines Objekts in Zeile 60. Das wäre ... if (swipeControl.swipedRight && idle == true) –