Add a flag to determine if the player has been stopped. At that point, stop setting the players position to the camera's, and instead some other input.
public float speed;
public test testing;
bool stopped = false;
// Use this for initialization
void Start () {
speed = 10f;
testing = Camera.main.GetComponent<test>();
}
// Update is called once per frame
void FixedUpdate () {
if (!stopped)
{
Vector3 p = Camera.main.ViewportToWorldPoint(new Vector3(0.5F, 0.5F, Camera.main.nearClipPlane));
transform.position = new Vector3(p.x, p.y, -1);
}
else
{
//move away here
}
}
void OnCollisionEnter2D(Collision2D col) {
stopped = true;
testing.speed = 0;
}
void OnCollisionExit2D(Collision2D col) {
stopped = false;
testing.speed = 10f;
}