Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'Scripting' started by jjthegamertv, May 12, 2020.

  1. jjthegamertv

    jjthegamertv

    Joined:
    Apr 17, 2020
    Posts:
    7
    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.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraFollow : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     public Transform leftBounds;
    9.     public Transform rightBounds;
    10.     public float smoothDampTime = 0.15f;
    11.  
    12.     private Vector3 smoothDampVelocity = Vector3.zero;
    13.     private float camWidth, camHeight, levelMinX, levelMaxX;
    14.  
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.         camHeight = Camera.main.orthographicSize * 2;
    20.         camWidth = camHeight * Camera.main.aspect;
    21.      
    22.         float leftBoundsWidth = leftBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
    23.         float rightBoundsWidth = rightBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
    24.      
    25.         levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth/2);
    26.         levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth/2);
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         if (target) {
    33.          
    34.             float targetX = Mathf.Max (levelMinX, Mathf.Min(levelMaxX. target.position.x));
    35.          
    36.             float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity.x, smoothDampTime);
    37.          
    38.             transform.position = new Vector3(x, transform.position.y, transform.position.z);
    39.         }
    40.     }
    41. }
    42.  
    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
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    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.
     
  3. jjthegamertv

    jjthegamertv

    Joined:
    Apr 17, 2020
    Posts:
    7
    Oh thanks. It's always the little things that makes big problems.
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    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)); 
     
    Joe-Censored likes this.
  5. jjthegamertv

    jjthegamertv

    Joined:
    Apr 17, 2020
    Posts:
    7
    Yeah, csofranz told me in a post above