OnMouseDown randomly stopping

Hey everyone,

I am working on a project for someone, and I ran across this issue, and it isn't making a lot of sense to me. I am moving an object around with my mouse, basically a click and drag thing. It will work when it is in the middle area of the field, but if it gets to close to the corners it just stops responding to clicks, so I pause it, move it to the middle area again, and it works fine. Any idea what might cause this weird error? The moving object has a box collider, mesh renderer and rigidbody. I would guess the script isn't important here, but I will post it anyways.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Paddle : MonoBehaviour {

public float moveSpeed = 0;
public RaycastHit hit;
public Ray ray;
public Vector3 newpos;
public Vector3 currentPosition;
public bool stateMove = false;
public bool first = false;
public int index = 0;
public int iterate = 0;
public Vector3[] holder = new Vector3[50];
public List<Vector3> list = new List<Vector3>();

void Start () {
    hit = new RaycastHit();
    newpos = transform.position;
    currentPosition = transform.position;
}

void Update () {
    if(stateMove)
    {
        if(iterate != 0)
        {
            list.Clear();
        }
        iterate = 0;
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        currentPosition = transform.position;

        if (Physics.Raycast(ray, out hit, 1000.0f)) {
            newpos = new Vector3(hit.point.x, 0.54f, hit.point.z);
        }
        list.Add(newpos);
    }
    else
    {
        if(iterate <  holder.Length && holder[iterate] != new Vector3(0,0,0))
        {
            moveSpeed += Time.deltaTime;
            transform.position = Vector3.MoveTowards(currentPosition, holder[iterate], moveSpeed*5);
            if(holder[iterate] == transform.position)
            {
                currentPosition = transform.position;
                iterate++;
                moveSpeed = 0;
                //first = false;
            }
        }
    }
}

void OnCollisionEnter(Collision collision){
    if(collision.gameObject.name == "CubeHorizontal" || collision.gameObject.name == "Cube"){

    }
}
void OnMouseDown()
{
    BreakoutGame.SP.SetMovementState();
    stateMove = true;
}
void OnMouseUp()
{
    BreakoutGame.SP.OffMovementState();
    stateMove = false;
    holder = list.ToArray();

}

}

Any ideas?

Do you have any other collider that doesn't have a renderer, maybe to control bounds. If so it might be getting in the way near the edges of the screen.

Gonna look at the script next.

Edit:

The problem seems to coming from this:

if (Physics.Raycast(ray, out hit, 1000.0f))
{
newpos = new Vector3(hit.point.x, 0.54f, hit.point.z);
}

It doesn't seem like it can get very far from the object. The value just stops.

I would honestly try a different approach than this. A move to click or follow the mouse while the button is down type of thing.

First thing I would do is narrow it down to where the bug could be. Add some Debug.Log() to OnMouseDown() and OnMouseUp(). That will determine if there is a problem in the input or your update function. My guess is in the update. I would then log out your list positions in your on mouse up.

 for(int i = 0; i < holder.Length; i++)
 {
        Debug.Log(holder*);*
 *}*
*```*
*<p>Hope this helps. Just keep narrowing it down till you find the culprit.</p>*