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?