Hi, I’ve spent about 3 hours trying every single possible way of doing this but nothing seems to work.
I have an object with a mesh collider and rigidbody.
Iam moving this object on Z with 2 touch controls (android platform)
Script for moving:
var leftcontrol : GUITexture;
var rightcontrol : GUITexture;
function awake(){
leftcontrol = GameObject.Find("GUIleft").guiTexture;
leftcontrol = GameObject.Find("GUIright").guiTexture;
}
function Start () {
}
function Update () {
for (var touch : Touch in Input.touches)
{
if (touch.phase == TouchPhase.Stationary && leftcontrol.HitTest (touch.position)){
transform.position.z -= 10;
}}
for (var touch : Touch in Input.touches)
{
if (touch.phase == TouchPhase.Stationary && rightcontrol.HitTest (touch.position)){
transform.position.z += 10;
}
}
}
and then there are 2 objects with box colliders that are supposed to block the object from moving too far but it just isnt working.
The Collision isnt working by itself so I tried adding this script but it isnt working either.
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "lWall"){
transform.position.z += 10;
}
if(theCollision.gameObject.name == "rWall"){
transform.position.z -= 10;
}
}
Any suggestions?