Search Unity

Bug code isnt working cant find error

Discussion in 'Scripting' started by gretelle121, May 28, 2023.

  1. gretelle121

    gretelle121

    Joined:
    May 28, 2023
    Posts:
    1
    errors:
    Assets\pipespwanscript.cs(25,10): error CS8641: ‘else’ cannot start a statement
    Assets\pipespwanscript.cs(25,10): error CS1003: Syntax error, ‘(‘ expected
    Assets\pipespwanscript.cs(25,10): error CS1525: Invalid expression term ‘else’
    Assets\pipespwanscript.cs(25,10): error CS1026: ) expected
    Assets\pipespwanscript.cs(25,10): error CS1002: ; expected

    code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class pipespwanscript : MonoBehaviour
    {
    public GameObject pipe;
    public float spawnRate = 2;
    private float timer = 0;
    public float heightOffset = 10;
    // Start is called before the first frame update
    void Start()
    {
    spawnPipe();
    }
    // Update is called once per frame
    void Update()
    {
    if (timer < spawnRate) ;
    {
    timer = timer + Time.deltaTime;
    }
    else
    {
    spawnPipe(false);
    timer = 0;
    }
    }
    void spawnPipe()
    {
    float lowestPoint = transform.position.y - heightOffset;
    float highestPoint = transform.position.y + heightOffset;
    Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0) , transform.rotation);
    }
    }