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

Assets\StickManDragger.cs(11,22): error CS0030: Cannot convert type 'method' to 'Vector2'

Discussion in '2D' started by Atskas, Aug 19, 2020.

  1. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    I tried to make a ragdoll game and had the idea of making it a fun draggable ragdoll as my first game,tried making the drag script but i get this error: error CS0030: Cannot convert type 'method' to 'Vector2'

    Here is the script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class StickManDragger : MonoBehaviour
    6. {
    7.     Vector2 difference = Vector2.zero;
    8.  
    9.     private void OnMouseDown()
    10.     {
    11.         difference = (Vector2)Camera.main.ScreenToWorldPoint - (Vector2)transform.position;
    12.     }
    13.  
    14.     private void OnMouseDrag()
    15.     {
    16.         transform.position = (Vector2) Camera.main.ScreenToWorldPoint(Input.mousePosition) - difference;
    17.     }
    18.  
    19.  
    20. }
     
  2. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    difference = (Vector2)Camera.main.ScreenToWorldPoint - (Vector2)transform.position;
    this should be:
    difference = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - (Vector2)transform.position;
     
  3. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    TY!