Search Unity

Prefabs share same variables (but not declared as static) - code included

Discussion in 'Prefabs' started by Mika857, Oct 10, 2019.

  1. Mika857

    Mika857

    Joined:
    Sep 7, 2019
    Posts:
    3
    Hey,

    I made a ui-system, which instantiate based on a list certain prefabs with the script item attached. If I go over one of these prefabs on every other prefab the variable selected goes to selected which shouldn't.
    Where have I made a mistake?
    (Unity version 2019.2.8)
     

    Attached Files:

  2. Mika857

    Mika857

    Joined:
    Sep 7, 2019
    Posts:
    3
    If you need more of my code contact me.
     
  3. Mika857

    Mika857

    Joined:
    Sep 7, 2019
    Posts:
    3
    Ohh I see the problem is that raycast can detect not only the object itself. But how could I do this, that the prefab's raycasts can only detect itself?
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The raycast needs to be restricted to the physics scene the Prefab is in. You can use this (where
    gameObject
    is a GameObject that's part of the Prefab):
    Code (CSharp):
    1. gameObject.scene.GetPhysicsScene().Raycast(...);