The question is answered, right answer was accepted
create action on touch release
I am loking to get an action of my model moving forward on finger release of the screen
can anyone help, this is my code so far and it only works if i hold the screen, i want it to work when you remove your finger from the screen.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class tap : MonoBehaviour
 {
     public float moveSpeed = 5.0f;
     public float drag = 0.5f;
     public Rigidbody controller;
     public GameObject player;
     public float speed;
     public float boost;
     public float damp;
 
 
 
 
     private void Start()
 
 
     {
         controller = GetComponent<Rigidbody>();
         controller.drag = drag;
     }
     private void Update()
     {
 
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary)
         {
             Vector2 touchPosition = Input.GetTouch(0).position;
 
 
             player.transform.Translate(Vector3.forward * 5 * Time.deltaTime);
 
         }
 
         Vector3 dir = Vector3.zero;
         dir.x = Input.GetAxis("Horizontal");
         dir.z = Input.GetAxis("Vertical");
         if (dir.magnitude > 1)
             dir.Normalize();
         controller.AddForce(dir * moveSpeed);
     }
 }
 
              Answer by Vollmondum · Mar 21, 2019 at 10:02 AM
 public bool move;
 
 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
 {
 move = !move;
 }
 
 if(move)
          {
              player.transform.Translate(Vector3.forward * 5 * Time.deltaTime);
          }
 
              Thank you,
would i need to remove any of my script to make this work?
sorry trying to place it into my script and i am rather new to this and i seem to be getting this error
Assets/Test.cs(34,16): error CS0165: Use of unassigned local variable `move'
thanks for the response
 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  public class tap : $$anonymous$$onoBehaviour
  {
      public float moveSpeed = 5.0f;
      public float drag = 0.5f;
      public Rigidbody controller;
      public GameObject player;
      public float speed;
      public float boost;
      public float damp;
      public bool move;
      private Vector3 dir;
  
  
       void Start() 
      {
          controller = GetComponent<Rigidbody>();
          controller.drag = drag;
      }
      void Update()
      {
           if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
           {
                 move = !move;
            }
  
           if(move)
           {
               player.transform.Translate(Vector3.forward * 5 * Time.deltaTime);
           }
  
          dir.x = Input.GetAxis("Horizontal");
          dir.z = Input.GetAxis("Vertical");
          if (dir.magnitude > 1)
          {
               dir.Normalize();
               controller.AddForce(dir * moveSpeed);
           }
      }
  }
 
                  thank you so much! this is amazing help, the code works but my player endless runs when you tap when i want it to be a multi tap run, so if it was tapped once it would evetually show down, i was hoping the drag would work with the use of gravity on the rigid body, would this need more script or would it be something i can figure out in the inspector, sorry for asking a lot of questions.
dont want you to feel like i am just asking for answers so feel free to point me in the direction of a good tutorial, on this if easier for you
Follow this Question
Related Questions
Help with js conversion to c# 1 Answer
Why aren't my scripts updating in my project? 1 Answer
make a gameobject move to another gameobject that was selected by mouse click? 1 Answer
Why is my Camera not rotating properly? 1 Answer
How to Destroy game object horizontally and vertically , when hit by a Raycast 0 Answers