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

resouces.load not working properly

Discussion in 'Prefabs' started by rdsp007, Apr 20, 2020.

  1. rdsp007

    rdsp007

    Joined:
    Dec 19, 2019
    Posts:
    4
    Hi,
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.SceneManagement;
    6. public class SearchMiscrits : MonoBehaviour
    7. {
    8.     private SpriteRenderer spriteRenderer;
    9.     private Color color;
    10.     public Texture2D cursorTexture;
    11.     public CursorMode cursorMode = CursorMode.Auto;
    12.     public Vector2 hotSpot = Vector2.zero;
    13.     private Vector3 mousePosition;
    14.     private GameObject instanced;
    15.     private bool temp;
    16.  
    17.     private void Start()
    18.     {
    19.         spriteRenderer = GetComponent<SpriteRenderer>();
    20.         color = spriteRenderer.color;
    21.        
    22.     }
    23.     private void Update()
    24.     {
    25.         mousePosition = Input.mousePosition;
    26.         mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
    27.  
    28.     }
    29.     private void OnMouseOver()
    30.     {
    31.         if (temp == true)
    32.         {
    33.             instanced = Instantiate(Resources.Load("Untitled-1", typeof(GameObject))) as GameObject;
    34.             instanced.transform.position = mousePosition;
    35.             temp = false;
    36.         }
    37.         cursorTexture = (Texture2D)Resources.Load("cuuu");
    38.         Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
    39.         spriteRenderer.color = new Color(241f / 255f, 235f / 255f, 149f / 255f);
    40.         if (Input.GetMouseButtonDown(0))
    41.         {
    42.             SceneManager.LoadScene("MiscritScene");
    43.         }
    44.     }
    45.     private void OnMouseExit()
    46.     {
    47.         temp = true;
    48.         spriteRenderer.color = color;
    49.         Cursor.SetCursor(null, hotSpot, cursorMode);
    50.         Destroy(instanced);
    51.     }
    52.  
    53. }
    54.  
    I am trying to instantiate an object with the resources.load on unity..
    but when i press play my instantiated object show up on scene and not in game window..can anyone figure this out??
     
  2. rdsp007

    rdsp007

    Joined:
    Dec 19, 2019
    Posts:
    4
    it is solved it was because of the near value of camera