This is technically 2 questions but I may as well kill 2 birds with 1 stone. In my game I want the cameras glitch filter effect to increase the closer it is to a gameobject. I have tried achieving this by using a waypoint script that i got and where it writes down the metres to the gameobject I thought I could update the glitches glitch effect accordingly. I have looked at many questions and forums about changing a float from another script but for some reason it still cant find the script. Both scripts are under the same object which is the camera. This should hopefully be one of my last questions for I have been asking alot lately. Any help would be deeply appreciated! Also the main part of the waypoint script that calls the color drift is at the bottom as well. Here is the waypoint script:
// Indicator icon
public Image img;
// The target (location, enemy, etc..)
public Transform target;
// UI Text to display the distance
public Text meter;
// To adjust the position of the icon
public Vector3 offset;
private void Update()
{
// Giving limits to the icon so it sticks on the screen
// Below calculations witht the assumption that the icon anchor point is in the middle
// Minimum X position: half of the icon width
float minX = img.GetPixelAdjustedRect().width;
// Maximum X position: screen width - half of the icon width
float maxX = Screen.width - minX;
// Minimum Y position: half of the height
float minY = img.GetPixelAdjustedRect().height;
// Maximum Y position: screen height - half of the icon height
float maxY = Screen.height - minY;
// Temporary variable to store the converted position from 3D world point to 2D screen point
Vector2 pos = Camera.main.WorldToScreenPoint(target.position + offset);
// Check if the target is behind us, to only show the icon once the target is in front
if (Vector3.Dot((target.position - transform.position), transform.forward) < 0)
{
// Check if the target is on the left side of the screen
if (pos.x < Screen.width / 2)
{
// Place it on the right (Since it's behind the player, it's the opposite)
pos.x = maxX;
}
else
{
// Place it on the left side
pos.x = minX;
}
}
// Limit the X and Y positions
pos.x = Mathf.Clamp(pos.x, minX, maxX);
pos.y = Mathf.Clamp(pos.y, minY, maxY);
// Update the marker's position
img.transform.position = pos;
// Change the meter text to the distance with the meter unit 'm'
meter.text = ((int)Vector3.Distance(target.position, transform.position)).ToString() + "m";
if ((int)Vector3.Distance(target.position, transform.position))
{
AnalogGlitch.colorDrift + 0.001;
}
}
using UnityEngine;
namespace Kino
{
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Kino Image Effects/Analog Glitch")]
public class AnalogGlitch : MonoBehaviour
{
#region Public Properties
// Scan line jitter
[SerializeField, Range(0, 1)]
float _scanLineJitter = 0;
public float scanLineJitter
{
get { return _scanLineJitter; }
set { _scanLineJitter = value; }
}
// Vertical jump
[SerializeField, Range(0, 1)]
float _verticalJump = 0;
public float verticalJump
{
get { return _verticalJump; }
set { _verticalJump = value; }
}
// Horizontal shake
[SerializeField, Range(0, 1)]
float _horizontalShake = 0;
public float horizontalShake
{
get { return _horizontalShake; }
set { _horizontalShake = value; }
}
// Color drift
[SerializeField, Range(0, 1)]
public float _colorDrift = 0;
public float colorDrift
{
get { return _colorDrift; }
set { _colorDrift = value; }
}
enter code here
enter code here
getComponent<AnalogGlitch>? (docs.unity3d.com/ScriptReference/GameObject.GetComponent.html) \$\endgroup\$AnalogGlitch Drift = gameObject.GetComponent<AnalogGlitch>(); // Change the meter text to the distance with the meter unit 'm' meter.text = ((int)Vector3.Distance(target.position, transform.position)).ToString() + "m"; if ((int)Vector3.Distance(target.position, transform.position)) { Drift._colorDrift + 1; }this gets more errors then before... Im not sure if this is correct but yeah. I'm still a bit new to code. \$\endgroup\$Drift._colorDrift + 1;you will increment a number but you will not store it anywhere and it will not update any variable. You'll need to assign it:Drift._colorDrift = Drift._colorDrift + 1;. I see you have at least 20 rep across the network. If you have issues with programming, I suggest you hit us in chat. It's a bit better suited for this kind of issue (with the back-and-forth). \$\endgroup\$