I was coding a gameObject can follow the mouse position but the gameObject disappear after starting the test. I have tried to change or add someting to my code but nothing change.
Honestly i should try the unity’s UI. Set up a canvas and put an image with the sword sprite or image and let it follow your mouse. I am not sure but it should follow input.MousePosition like that. I do not know why is vanishes. Are you making the gameobjects while in playmode or do you have other scripts that might alter the gameobject?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseFollow : MonoBehaviour
{
public GameObject Sword;
public Vector2 mousePosition;
void Update()
{
mousePosition = Input.mousePosition;
Sword.transform.position = new Vector2(mousePosition.x, mousePosition.y);
Debug.Log("Mouse's position : " + mousePosition);
Debug.Log("Object's position :" + Sword.transform.position);
}
}