Search Unity

error CS1729

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

  1. jiteshGD

    jiteshGD

    Joined:
    Jan 26, 2020
    Posts:
    16
    Assets\Scripts\Level.cs(60,25): error CS1729: 'Level.Pipe' does not contain a constructor that takes 2 arguments.
    I got this error and I don't know the solutuon. please guide me.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Level : MonoBehaviour {
    6.     private const float CAMERA_ORTHO_SIZE = 50f;
    7.     private const float PIPE_WIDTH = 13.4f;
    8.     private const float PIPE_HEAD_HEIGHT = 7.2f;
    9.     private const float PIPE_MOVE_SPEED = 3f;
    10.     private List<Pipe> pipeList;
    11.  
    12.     private void Awake () {
    13.         pipeList = new List<Pipe> ();
    14.     }
    15.  
    16.     private void Start () {
    17.         //CreatePipe(50f, 20f, true);
    18.         //CreatePipe(50f, 20f, false);
    19.         CreateGapPipes (50f, 20f, 20f);
    20.     }
    21.     private void Update () {
    22.         HandlePipeMovement ();
    23.     }
    24.     private void HandlePipeMovement () {
    25.         foreach (Pipe pipe in pipeList) {
    26.             pipe.Move ();
    27.         }
    28.     }
    29.     private void CreateGapPipes (float gapY, float gapSize, float xPosition) {
    30.         CreatePipe (gapY - gapSize * 0.5f, xPosition, true);
    31.         CreatePipe (CAMERA_ORTHO_SIZE * 2f - gapY - gapSize * 0.5f, xPosition, false);
    32.     }
    33.     private void CreatePipe (float height, float xPosition, bool createBottom) {
    34.         Transform pipeHead = Instantiate (GameAssets.GetInstance ().pfPipeHead);
    35.         float pipeHeadYPosition;
    36.         if (createBottom) {
    37.             pipeHeadYPosition = -CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * .5f;
    38.         } else {
    39.             pipeHeadYPosition = +CAMERA_ORTHO_SIZE - height + PIPE_HEAD_HEIGHT * .5f;
    40.         }
    41.         pipeHead.position = new Vector3 (xPosition, pipeHeadYPosition);
    42.  
    43.         Transform pipeBody = Instantiate (GameAssets.GetInstance ().pfPipeBody);
    44.         float pipeBodyYPositon;
    45.         if (createBottom) {
    46.             pipeBodyYPositon = -CAMERA_ORTHO_SIZE;
    47.         } else {
    48.             pipeBodyYPositon = +CAMERA_ORTHO_SIZE;
    49.             pipeBody.localScale = new Vector3 (1, -1, 1);
    50.         }
    51.         pipeBody.position = new Vector3 (xPosition, pipeBodyYPositon);
    52.  
    53.         SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent<SpriteRenderer> ();;
    54.         pipeBodySpriteRenderer.size = new Vector2 (PIPE_WIDTH, height);
    55.  
    56.         BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent<BoxCollider2D> ();
    57.         pipeBodyBoxCollider.size = new Vector2 (PIPE_WIDTH, height);
    58.         pipeBodyBoxCollider.offset = new Vector2 (0f, height * 0.5f);
    59.  
    60.         Pipe pipe = new Pipe (pipeHead, pipeBody);
    61.         pipeList.Add (pipe);
    62.     }
    63.     private class Pipe {
    64.         private Transform pipeHeadTransform;
    65.         private Transform pipeBodyTransform;
    66.         public void pipe (Transform pipeHeadTransform, Transform pipeBodyTransform) {
    67.             this.pipeHeadTransform = pipeHeadTransform;
    68.             this.pipeBodyTransform = pipeBodyTransform;
    69.         }
    70.         public void Move () {
    71.             pipeHeadTransform.position += new Vector3 (-1, 0, 0) * PIPE_MOVE_SPEED * Time.deltaTime;
    72.             pipeBodyTransform.position += new Vector3 (-1, 0, 0) * PIPE_MOVE_SPEED * Time.deltaTime;
    73.         }
    74.     }
    75. }
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    remove 'void' in the constructor

    Code (CSharp):
    1. public void pipe (Transform pipeHeadTransform, Transform pipeBodyTransform)
     
  3. jiteshGD

    jiteshGD

    Joined:
    Jan 26, 2020
    Posts:
    16
    After removing void it is showing now this Assets\Scripts\Level.cs(66,16): error CS1520: Method must have a return type
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Level : MonoBehaviour {
    6.     private const float CAMERA_ORTHO_SIZE = 50f;
    7.     private const float PIPE_WIDTH = 13.4f;
    8.     private const float PIPE_HEAD_HEIGHT = 7.2f;
    9.     private const float PIPE_MOVE_SPEED = 3f;
    10.     private List<Pipe> pipeList;
    11.  
    12.     private void Awake () {
    13.         pipeList = new List<Pipe> ();
    14.     }
    15.  
    16.     private void Start () {
    17.         //CreatePipe(50f, 20f, true);
    18.         //CreatePipe(50f, 20f, false);
    19.         CreateGapPipes (50f, 20f, 20f);
    20.     }
    21.     private void Update () {
    22.         HandlePipeMovement ();
    23.     }
    24.     private void HandlePipeMovement () {
    25.         foreach (Pipe pipe in pipeList) {
    26.             pipe.Move ();
    27.         }
    28.     }
    29.     private void CreateGapPipes (float gapY, float gapSize, float xPosition) {
    30.         CreatePipe (gapY - gapSize * 0.5f, xPosition, true);
    31.         CreatePipe (CAMERA_ORTHO_SIZE * 2f - gapY - gapSize * 0.5f, xPosition, false);
    32.     }
    33.     private void CreatePipe (float height, float xPosition, bool createBottom) {
    34.         Transform pipeHead = Instantiate (GameAssets.GetInstance ().pfPipeHead);
    35.         float pipeHeadYPosition;
    36.         if (createBottom) {
    37.             pipeHeadYPosition = -CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * .5f;
    38.         } else {
    39.             pipeHeadYPosition = +CAMERA_ORTHO_SIZE - height + PIPE_HEAD_HEIGHT * .5f;
    40.         }
    41.         pipeHead.position = new Vector3 (xPosition, pipeHeadYPosition);
    42.  
    43.         Transform pipeBody = Instantiate (GameAssets.GetInstance ().pfPipeBody);
    44.         float pipeBodyYPositon;
    45.         if (createBottom) {
    46.             pipeBodyYPositon = -CAMERA_ORTHO_SIZE;
    47.         } else {
    48.             pipeBodyYPositon = +CAMERA_ORTHO_SIZE;
    49.             pipeBody.localScale = new Vector3 (1, -1, 1);
    50.         }
    51.         pipeBody.position = new Vector3 (xPosition, pipeBodyYPositon);
    52.  
    53.         SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent<SpriteRenderer> ();;
    54.         pipeBodySpriteRenderer.size = new Vector2 (PIPE_WIDTH, height);
    55.  
    56.         BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent<BoxCollider2D> ();
    57.         pipeBodyBoxCollider.size = new Vector2 (PIPE_WIDTH, height);
    58.         pipeBodyBoxCollider.offset = new Vector2 (0f, height * 0.5f);
    59.  
    60.         Pipe pipe = new Pipe (pipeHead, pipeBody);
    61.         pipeList.Add (pipe);
    62.     }
    63.     private class Pipe {
    64.         private Transform pipeHeadTransform;
    65.         private Transform pipeBodyTransform;
    66.         public pipe (Transform pipeHeadTransform, Transform pipeBodyTransform) {
    67.             this.pipeHeadTransform = pipeHeadTransform;
    68.             this.pipeBodyTransform = pipeBodyTransform;
    69.         }
    70.         public void Move () {
    71.             pipeHeadTransform.position += new Vector3 (-1, 0, 0) * PIPE_MOVE_SPEED * Time.deltaTime;
    72.             pipeBodyTransform.position += new Vector3 (-1, 0, 0) * PIPE_MOVE_SPEED * Time.deltaTime;
    73.         }
    74.     }
    75. }
     
  4. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    C# is case sensitive, so you should have public Pipe instead of public pipe