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

Question transform.position assign for 'BackgroundWind <My Object's Name>' is not valid. Input position is...

Discussion in 'Documentation' started by rev1z, Jan 24, 2021.

  1. rev1z

    rev1z

    Joined:
    Jan 24, 2021
    Posts:
    7
    Hello unity forum heros. I need help. I can't solve this problem.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Background : MonoBehaviour
    4. {
    5.     private float move = 10.0f;
    6.     private float forTimes, forTimes0 = 30.0f;
    7.     private float wait = 0.2f;
    8.     private bool positive = true;
    9.     private float smooth;
    10.  
    11.     private Transform tf;
    12.  
    13.     void Start()
    14.     {
    15.         tf = GetComponent<Transform>();
    16.         smooth = move / forTimes;
    17.         InvokeRepeating("BackgroundMove", wait, wait);
    18.     }
    19.  
    20.     private void BackgroundMove()
    21.     {
    22.         if (forTimes > 0)
    23.         {
    24.             print("selam");
    25.             tf.position = new Vector3(tf.position.x, tf.position.y + smooth); // HERE
    26.             print(tf.position);
    27.             forTimes--;
    28.         }
    29.         else if (forTimes < 0)
    30.         {
    31.             if (forTimes > 0)
    32.                 forTimes *= -1;
    33.             tf.position.Set(tf.position.x, tf.position.y + smooth, tf.position.z); ;
    34.             forTimes++;
    35.         }
    36.         else
    37.         {
    38.             if (positive)
    39.             {
    40.                 forTimes = -1 * forTimes0;
    41.                 positive = !positive;
    42.             }
    43.             else
    44.             {
    45.                 forTimes = forTimes0;
    46.                 positive = !positive;
    47.             }
    48.         }
    49.     }
    50. }
     

    Attached Files:

  2. rev1z

    rev1z

    Joined:
    Jan 24, 2021
    Posts:
    7
    I solve it.

    private float forTimes = 30;
    private float forTimes0 = 30;
    that's be enough.
     
  3. fgrhtjr

    fgrhtjr

    Joined:
    Feb 28, 2021
    Posts:
    2
    Last edited: Mar 1, 2021