Search Unity

error CS0501

Discussion in 'Scripting' started by jiteshGD, Feb 3, 2020.

  1. jiteshGD

    jiteshGD

    Joined:
    Jan 26, 2020
    Posts:
    16
    I am not getting where i got wrong please solve this please.
    Assets\Scripts\Pipes.cs(8,31): error CS0501: 'Pipes.Pipe()' must declare a body because it is not marked abstract, extern, or partial
    This is the I am getting.
    The script is below
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Pipes : MonoBehaviour
    {
    public float shiftSpeed = 1;
    private static void Pipes.Pipe();
    Transform selfTransform;
    // Start is called before the first frame update
    void Start()
    {
    selfTransform = transform;
    }

    // Update is called once per frame
    void Update()
    {

    Pipes.transform.position += Vector3.left * shiftSpeed * Time.deltaTime;

    }
    }
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Should be.
    Code (CSharp):
    1. private static void Pipe()
    2. {
    3. }
    Methods unless they are declared as abstract must have a body which is basically { }.
     
  3. jiteshGD

    jiteshGD

    Joined:
    Jan 26, 2020
    Posts:
    16
    After doing that I got another error
    Assets\Scripts\Piipe.cs(22,1): error CS0120: An object reference is required for the non-static field, method, or property 'Component.transform'
     

    Attached Files:

    • Piipe.cs
      File size:
      453 bytes
      Views:
      276
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    In Update you are trying to access a non static field through a static accessor.

    Change Update to this.
    Code (CSharp):
    1. void Update()
    2. {
    3.     transform.position += Vector3.left * shiftSpeed * Time.deltaTime;
    4. }