- Home /
error CS0122: `UnityEngine.Transform.Transform()' is inaccessible due to its protection level
I've been looking at people with the same issue and how they solved it but it's not working for me. Here's my code; do you think you can help me: using UnityEngine; using UnityEngine.UI; using System.Collections;
public class CameraMouse : MonoBehaviour {
public float distance = 5.0f;
public float xSensitivity = 5.0f;
public float ySensitivity = 5.0f;
public float xAngle = 0.0f;
public float yAngle = 0.0f;
public int target = new Transform();
void LateUpdate ()
{
// Only if there is a target
if (target) {
if (Input.GetMouseButton (1))
// Update x, y angle with the mouse delta
yAngle -= Input.GetAxis ("Mouse Y") * ySensitivity;
if (Input.GetMouseButton (1))
xAngle += Input.GetAxis ("Mouse X") * xSensitivity;
yAngle = Mathf.Clamp (yAngle, 0, 90);
// Initialize the position to be distance units along the z axis
// away from the target
transform.position = Vector3.forward * distance + target.position;
// Initialize the rotation to look at the target
transform.LookAt (target.position);
// Rotate around the world up axis by the accumulated delta mouse x
transform.RotateAround (target.position, Vector3.up, xAngle);
// Rotate around our own right vector by the accumulated delta mouse y
worldRight = transform.TransformDirection (Vector3.right);
transform.RotateAround (target.position, worldRight, yAngle);
}
}
}
thanks!
Comment
You cannot call constructors for $$anonymous$$onoBehaviours OR ScriptableObjects. You must use AddComponent<Transform>();
Answer by gjf · Mar 19, 2017 at 06:00 PM
this line:
public int target = new Transform()
is the problem - you cannot make a new Transform
of type int
Additionally, you shouldn't be calling the constructor for Transform or any other Component.
Pretty sure you can't create a new Transform() full stop?
Your answer
![](https://koobas.hobune.stream/wayback/20220612113519im_/https://answers.unity.com/themes/thub/images/avi.jpg)