- Home /
MissingComponentException: There is no 'Camera'
MissingComponentException: There is no 'Camera' attached to the "CoinPrefab" game object, but a script is trying to access it. You probably need to add a Camera to the game object "CoinPrefab". Or your script needs to check if the component is attached before using it. UnityEngine.Camera.set_pixelRect (Rect value) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/UnityEngineCamera.cs:213) PictireInPicture.AdjustCamera () (at Assets/MyScripts/PictireInPicture.cs:82) PictireInPicture.Update () (at Assets/MyScripts/PictireInPicture.cs:32)
The thing is, i dont want a camera on the coinprefab, and none of my code is asking for it. i have NO idea where this error is coming from and why it randomly wants a camera, it keeps SPAMMING this warning while in play mode
using UnityEngine;
using System.Collections;
public class PictireInPicture : MonoBehaviour {
public enum HorizontalAlignment{left, center, right};
public enum VerticalAlignment{top,middle,bottom};
public HorizontalAlignment horizontalAlignment = HorizontalAlignment.left;
public VerticalAlignment verticalAlignment = VerticalAlignment.top;
public enum ScreenDimensions{pixels,screen_percentage};
public ScreenDimensions dimensionsIn = ScreenDimensions.screen_percentage;
public int width = 50;
public int height = 50;
public float xOffset = 0f;
public float yOffset = 0f;
public bool update = true;
private int hsize, vsize, hloc , vloc;
// Use this for initialization
void Start ()
{
AdjustCamera ();
}
// Update is called once per frame
void Update ()
{
if (update)
{
AdjustCamera();
}
}
void AdjustCamera()
{
if (dimensionsIn == ScreenDimensions.screen_percentage)
{
hsize = Mathf.RoundToInt(width * 0.01f * Screen.width);
vsize = Mathf.RoundToInt(height * 0.01f * Screen.height);
}
else
{
hsize = width;
vsize = height;
}
if (horizontalAlignment == HorizontalAlignment.left)
{
hloc = Mathf.RoundToInt(xOffset * 0.01f * Screen.width);
}
else if (horizontalAlignment == HorizontalAlignment.right)
{
hloc = Mathf.RoundToInt(((Screen.width - hsize) - (xOffset * 0.01f * Screen.width)));
}
else
{
hloc = Mathf.RoundToInt((Screen.width * 0.5f) - (hsize * 0.5f) - (xOffset * 0.01f * Screen.width));
}
if (verticalAlignment == VerticalAlignment.top)
{
vloc = Mathf.RoundToInt(( Screen.height - vsize) - (yOffset * 0.01f * Screen.height));
}
else if (verticalAlignment == VerticalAlignment.bottom)
{
vloc = Mathf.RoundToInt(( yOffset * 0.01f * Screen.height));
}
else
{
vloc = Mathf.RoundToInt(((Screen.height * 0.5f) - (vsize * 0.5f)) - (yOffset * 0.01f * Screen.height));
}
camera.pixelRect = new Rect (hloc, vloc, hsize, vsize);
}
}
this is my minimap code, the problem seems to lie within
Line 82 is fine, its a code for a $$anonymous$$imap. it should work regardless if i have this prefab or not. NO idea why it wants a camera on it though
It is in fact line 82, as that references a camera component, which in your case does not seem to be attached.
it's referencing a campera component yes, it's my mapcamera that it's attached to, so that does not seem to be the case?
Your answer
Follow this Question
Related Questions
GameObject invisible at certain camera angles 0 Answers
OnBecameInvisible only running when game stops 2 Answers
First person view question 1 Answer
Camera Problem 0 Answers
How can I check if an object is seen by my camera and if i't inside a gui? 1 Answer