JoeyObee
JoeyObee

Reputation: 21

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 avariable', value' ormethod 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);
        }
    }
}

Upvotes: 0

Views: 117

Answers (2)

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

Upvotes: -1

Andrea
Andrea

Reputation: 6125

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).

Upvotes: 3

Related Questions