CS1061: 'float' does not contain a definition for 'target' and no ...

I’m back with another compile error, and this time its hopefully not just capitalisation. I think I have an idea on how to fix it but, I’ll leave it to the professionals.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform target;
    public Transform leftBounds;
    public Transform rightBounds;
    public float smoothDampTime = 0.15f;
  
    private Vector3 smoothDampVelocity = Vector3.zero;
    private float camWidth, camHeight, levelMinX, levelMaxX;
  
  
    // Start is called before the first frame update
    void Start()
    {
        camHeight = Camera.main.orthographicSize * 2;
        camWidth = camHeight * Camera.main.aspect;
      
        float leftBoundsWidth = leftBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
        float rightBoundsWidth = rightBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
      
        levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth/2);
        levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth/2);
    }

    // Update is called once per frame
    void Update()
    {
        if (target) {
          
            float targetX = Mathf.Max (levelMinX, Mathf.Min(levelMaxX. target.position.x));
          
            float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity.x, smoothDampTime);
          
            transform.position = new Vector3(x, transform.position.y, transform.position.z);
        }
    }
}

float targetX = Mathf.Max (levelMinX, Mathf.Min(levelMaxX. target.position.x)); is what seems to be the problem. Im thinking of changing float to transform but i don’t wanna get 50 more compile errors. Thanks to any of those who answer

You really should supply the full error description and indicate the line number in your code where it occurs. It saves a lot of hassle for anyone who might be inclined to help.

The error here is that you erroneously used a period ‘.’ after levelMaxX instead of a comma ‘,’ to separate levelMaxX from target in the Mathf.Min() function.

Yeah, compilers are finnicky that way.

Oh thanks. It’s always the little things that makes big problems.

You have a typo here, placing a period between the Mathf.Min parameters instead of a comma:
float targetX = Mathf.Max (levelMinX, Mathf.Min(levelMaxX. target.position.x));

1 Like

Yeah, csofranz told me in a post above