In this game (like in a catch game tutorial), hat is suppposed to move to the edge of the screen, but not in my case. You can move the hat left and right, but he is not touching the edge of the left side or the right side of the screen. Can someone please tell me what to change in the script in the way that hat can catch all the items that are falling from the sky. Thanks in advance…
PS (korpa stands for a hat)
This is my controller script:
using UnityEngine;
using System.Collections;
public class KorpaController : MonoBehaviour {
public Camera cam;
private float maxWidth;
private bool canControl;
// Use this for initialization
void Start () {
if (cam == null) {
cam = Camera.main;
}
canControl = false;
Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
float korpaWidth = renderer.bounds.extents.x;
maxWidth = targetWidth.x - korpaWidth;
}
void FixedUpdate () {
if (canControl){
Vector3 rawPosition = cam.ScreenToWorldPoint (Input.mousePosition);
Vector3 targetPosition = new Vector3 (rawPosition.x, 0.0f, 0.0f);
float targetWidth = Mathf.Clamp (targetPosition.x, -maxWidth, maxWidth);
targetPosition = new Vector3 (targetWidth, targetPosition.y, targetPosition.z);
rigidbody2D.MovePosition (targetPosition);
}
}
public void ToggleControl (bool toggle){
canControl = toggle;
}
}