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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

error CS0535

Discussion in 'Scripting' started by InsertNameH3re, May 23, 2021.

  1. InsertNameH3re

    InsertNameH3re

    Joined:
    Apr 18, 2021
    Posts:
    13
    Hello. I am programming a script to drag an object from one side to the other, but I get this error:
    Assets \ Scripts \ DragHandler.cs (6.74): error CS0535: 'DragHandler' does not implement interface member 'IBeginDragHandler.OnBeginDrag (PointerEventData)'

    How should i fix it?
    This is the script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class DragHandler : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
    7. {
    8.     public void OnBeginDraw(PointerEventData eventData)
    9.     {
    10.         Debug.log("OnBegindRAG");
    11.     }
    12.  
    13.     public void OnDrag(PointerEventData eventData)
    14.     {
    15.         Debug.Log("OnDrag");
    16.         tansform.position = Input.mousePosition;
    17.     }
    18.  
    19.     public void OnEndDrag(PointerEventData eventData)
    20.     {
    21.         Debug.Log("OnEndDrag");
    22.     }
    23.  
    24.     //Start is called before the first frame update
    25.     void Start()
    26.     {
    27.  
    28.     }
    29.  
    30.     //Update is called once per frame
    31.     void Update()
    32.     {
    33.  
    34.     }
    35. }
     
  2. luke_2

    luke_2

    Joined:
    Nov 20, 2012
    Posts:
    29
    Implement the method, e.g. add:

    Code (CSharp):
    1.     public void OnBeginDrag(PointerEventData eventData)
    2.     {
    3.         Debug.Log("OnBeginDrag");
    4.     }
     
  3. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    i think there is a typo in line 8
    you are implementing a function named "OnBeginDraw" but i m pretty sure you meant to write "OnBeginDrag"
     
  4. InsertNameH3re

    InsertNameH3re

    Joined:
    Apr 18, 2021
    Posts:
    13
    This gives a new error in line 16: The name 'tansform' does not exist in the current context
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Check your spelling, and please don't use this forum as your personal "typo correction service."

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation generally ends in disaster. That's how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
    JoNax97 likes this.