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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Help

Discussion in 'Scripting' started by jamfu123, Dec 13, 2018.

  1. jamfu123

    jamfu123

    Joined:
    Jul 30, 2018
    Posts:
    16
    Any reason why the < is an invalid expression term ? this is the error i am getting when trying to destroy an object when it leaves the boundaries of the screen

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PrefabSpawner : MonoBehaviour
    {
    public float speed = 10.0f;
    private Rigidbody rb;
    private Vector3 screenBounds;
    void Start()
    {
    rb = this.GetComponent<Rigidbody>();
    rb.velocity = new Vector3 ( 0,0,-1); //moves enemy left to right based on speed value
    screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
    }
    void Update()
    {
    if (transform.position.x is > screenBounds.x * 2) {
    Destroy(this.gameObject);
    }

    }
    }
     
  2. jamfu123

    jamfu123

    Joined:
    Jul 30, 2018
    Posts:
    16
    Nevermind, i noticed i had is there which was causing the error
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Great you got it working.

    Some tips for the future though: Please use code tags. It also helps when threads have a descriptive title.
     
    jamfu123 likes this.
  4. jamfu123

    jamfu123

    Joined:
    Jul 30, 2018
    Posts:
    16
    Thanks for that!