- Home /
HOW TO MAKE A 2D OBJECT MOVE WITH TOUCH INPUT ON ANOTHER
hey ...so i m making a small 2d game for android for a project..but i have a problem..i a using orthello the free sprite manager...so the problem is i want to have 2 texture at two ends of my screen at bottom and touching them should make the character move left and right..so the orthello have OT.Touched syntax to use for that which is cool..but the problem is that i cant make the character move ....i tried using bool nd then getcomponent on another script to check if it is touched but that results in an error NullRefrenceException:object refrence not set...so i am asking is there any way to make it work...nd plz i m new so jst explain a little bit ..i will be glad if u do so...nd thanx for helping.. my code in the 2nd script is this
using UnityEngine;
using System.Collections;
public class movementtouch : MonoBehaviour {
public touchinput script;
public int touch;
void Update () {
script= GetComponent("touchinput") as touchinput;
Debug.Log("1");
script.touch1.Equals(touch);
Debug.Log("2");
if(touch==1)
{
Debug.Log("BEAR MOVE");
}
}
}
I'm trying to do something similar. Could you give me the code you finally used? Thanks!
Answer by AlucardJay · Jul 25, 2012 at 02:28 PM
Check my answer here for rotating : http://answers.unity3d.com/questions/289055/rotate-on-drag-for-ios.html
And my answer here for movement : http://forum.unity3d.com/threads/142758-Moving-objects-with-your-finger
Your answer
Follow this Question
Related Questions
Touch Input on Sprites 1 Answer
Scaling giant images as 2D Sprite 0 Answers
Global input script vs own scripts for all gameObjects 0 Answers
Samsung 42" Touch Screen: Touch response issues 1 Answer
Problem with Input.touchCount 0 Answers