Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Generating touch programatically

Discussion in 'Scripting' started by CarlY, Apr 10, 2014.

  1. CarlY

    CarlY

    Joined:
    Nov 5, 2013
    Posts:
    29
    Hello,

    I'm implementing a simple replay system. I need to generate touch events, like generate touch event at screen location (100,50) programmatically. I just couldn't find a way to do it. Any thoughts?
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Did you considered to make something like a Wrapper or Adater and use it instead of using of touch input directly? I mean if your game will use touch wrapper instead of Input.touches, you could easy add to this wrapper coulpe of methods to record and simulate touches. ;-)
     
  3. CarlY

    CarlY

    Joined:
    Nov 5, 2013
    Posts:
    29
    Something like that would be too painful for me to implement. Somebody must have done something like this, maybe I'm using the wrong keywords.
     
  4. damian.doroba

    damian.doroba

    Joined:
    Apr 4, 2013
    Posts:
    36
    This kind of wrapper is not difficult to write, just create class with list containing touches and read from this list. If you wan't to generate event, simply add touch to this list.

    More interesting is if you use physic in your game. From my experience I know, that repeating input is not enough to replay physic - you need sample and synchronize physic (you can find tutorials from braid in internet)
     
  5. amodkanthe

    amodkanthe

    Joined:
    Mar 15, 2022
    Posts:
    4
    found any solution for this?
     
  6. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,739
    well this is a post from 2014 so pretty old one to bring back up. But also something i consider to be a XY Problem.

    instead of recording and mimicking inputs, the recording should be done on the layer after the inputs, that way you can record only what matters for your replay system.