// Use this for initialization private void Awake() { //Sets the static reference to this camera if one doesn't already exist if (thisCam == null) { thisCam = this; } //Initializes the list to hold weighted objects thisCam.weightObjects = new List <GameObject>(); //Makes sure the sum of weights starts at 0 thisCam.weightSum = 0; //Stores the reference to this object's camera component thisCam.weightCamera = GetComponent <Camera>(); }
// Use this for initialization public void Awake() { //If this should always remain on screen, adds it to the camera's list of objects to follow if (this.alwaysOnScreen) { CameraMount_FollowWeights.AddWeightedObject(this.gameObject); this.enabled = false; } //Makes sure the Drop Distance is greater than the Add Distance to prevent errors with the weight system if (this.dropDistance <= this.addDistance) { this.dropDistance = this.addDistance + 1; } //Gets the reference to the game object that the camera is on this.cameraRef = CameraMount_FollowWeights.thisCam.gameObject; }
//Adds and drops this object from the designated camera when it gets in or out of range and returns a bool based on if this object is being tracked by the camera private bool HandleCamera(GameObject cameraObj_, bool onCamera_) { //If the designated camera doesn't exist, nothing happens if (cameraObj_ == null) { return(false); } bool isOnScreen = onCamera_; //If this object is already being tracked by the designated camera, finds out if it should be dropped if (onCamera_) { Vector2 thisObjPos = new Vector2(this.transform.position.x, this.transform.position.y); Vector2 camObjPos = new Vector2(cameraObj_.transform.position.x, cameraObj_.transform.position.y); float dist = Vector2.Distance(thisObjPos, camObjPos); //If the distance is greater than the drop distance, it won't be tracked anymore if (dist >= this.dropDistance) { CameraMount_FollowWeights.DropWeightedObject(this.gameObject); isOnScreen = false; } } //If this object isn't being tracked by the designated camera, finds out if it should be added else { Vector2 thisObjPos = new Vector2(this.transform.position.x, this.transform.position.y); Vector2 camObjPos = new Vector2(cameraObj_.transform.position.x, cameraObj_.transform.position.y); float dist = Vector2.Distance(thisObjPos, camObjPos); //If the distance is less than the add distance, it will be tracked if (dist <= this.addDistance) { CameraMount_FollowWeights.AddWeightedObject(this.gameObject); isOnScreen = true; } } return(isOnScreen); }