- Home /
Touch and Drag for Android problem
I am working on 2d using orthello.
I have an object called as 'Wall' in the hierarchy and have attached this script 'Wall.cs'.
Below the wall is a 'background' object.
The code drags the background while the wall does not move at all. Isn't the keyword 'this' a reference to the wall instance since the class is a 'Wall'?
using UnityEngine;
using System.Collections;
public class Wall : MonoBehaviour {
void Update () {
int speed = 100;
if (Input.touches.Length > 0) {
// Only work with the first touch
// and only if the touch moved since last update
if (Input.touches[0].phase == TouchPhase.Moved)
{
float x = Input.touches[0].deltaPosition.x * speed * Time.deltaTime;
float y = Input.touches[0].deltaPosition.y * speed * Time.deltaTime;
this.transform.Translate(new Vector3(x, y, 0));
}
}
}
}
Hmm, looks correct to me. Is there any specific reason why you are using the 'this' keyword when you don't need to? I don't see how that can be causing the problem, but try removing it.
Figured it out. The background had this script attached to it grimace.
Your answer
Follow this Question
Related Questions
Touch - drag different objects 1 Answer
Drag and Swap two object using touch 0 Answers
Dragging Camera based on Touch 0 Answers
how create flipping book effect like apple ibook with touch ? 0 Answers
Ragdoll 2D character controller help 0 Answers