简体   繁体   中英

Unity C# unknown reason for error code

Sorry to be a pain, but I really can't for the life of me figure out whats wrong with my code. I am building a simple space shooting game in Unity, using C#.

The have written a script to tie to two planes, that will cause them to scroll as a background.

However, for some reason that I really cant figure out, I am getting the error code:

Assets/SCripts/parallaxScrolling.cs(26,46): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

Here's the code, thanks:

using UnityEngine;
using System.Collections;

public class parallaxScrolling : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    public float speed; //declare a variable for the movement speed overall


    // Update is called once per frame
    void Update () 
    {
        float move = speed * Time.deltaTime;

        transform.Translate (Vector3.down * move, Space.World); //this moves the object down at speed variable

        float heightLimit = -9;
        float yLimit = 11;

        if (transform.position.y <= heightLimit) 
        {
            transform.position = Vector2(transform.position.x,yLimit,transform.position.z);
        }
    }
}

You are using C#, so you have to declare objects with the new keyword, as your Vector3. That is, just add new in front of Vector3 (the one indicated as Vector2 in your code, in line 26).

transform.position = new Vector3(transform.position.x,yLimit,transform.position.z);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM