- Home /
Renderer.bounds.extenct.x; cant find bounds
i was doing the Catch game pt1 scripts, and whenever i type renderer. <-- i cant find bounds and there is an error..
float hatWidth = renderer.bounds.extents.x;
The whole thing
using UnityEngine;
using System.Collections;
public class HatController : MonoBehaviour {
public Camera cam;
private float maxWidth;
// Use this for initialization
void Start () {
if (cam == null) {
cam = Camera.main;
}
Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
float hatWidth = renderer.bounds.extents.x;
maxWidth = targetWidth.x - hatWidth;
}
// Update is called once per Physics timestep
void FixedUpdate () {
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);
transform.position = targetPosition;
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I check if an object is completely visible? 4 Answers
"Mesh 'NormalCurveRendererMesh': abnormal mesh bounds..." error appears on editor... 0 Answers
Renderer Bounds 3 Answers
Bounds larger than expected 1 Answer
Text with fixed size in viewport 1 Answer