Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question When I make copy of 1 specific scripted object it doesn’t work

Discussion in 'Getting Started' started by SidCanGame, Aug 24, 2023.

  1. SidCanGame

    SidCanGame

    Joined:
    Jul 19, 2023
    Posts:
    6
    I have 2 objects a ball and a ufo I want to copy paste the ufo multiple times around the map but then I every time I need to go back to the ball script and put a reverence to the game object and add some more script is there a way to do this with a gameobject array and set active? ps I am a beginner can you make instructions please?
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    We don't know what you doing with reference to UFO objects. This could be just a lack of development skills. You should ask yourself: Why do I need this reference there, and can I reverse logic? Maybe will be enough if you make a UFO script and inside will be a reference to one Ball object (reference one too many, not many to one).

    We need more info on what you want to do so we can give a more precise answer.
     
  3. SidCanGame

    SidCanGame

    Joined:
    Jul 19, 2023
    Posts:
    6
    this is the script I wrote inside the ufo but if I copy pate the object it doesn't work
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class doosje : MonoBehaviour
    6. {
    7.     public GameObject deksel;
    8.     public GameObject ball;
    9.     public bool isActive;
    10.     public Rigidbody2D _rb;
    11.     public bool collided;
    12.  
    13.     private void OnTriggerEnter2D(Collider2D collision)
    14.     {
    15.         collided = true;
    16.     }
    17.  
    18.     private void OnTriggerExit2D(Collider2D collision)
    19.     {
    20.         collided = false;
    21.     }
    22.     void Start()
    23.     {
    24.        
    25.         collided = false;
    26.     }
    27.  
    28.     // Update is called once per frame
    29.     void Update()
    30.     {
    31.         if ((Input.GetKeyDown(KeyCode.Q) && collided))
    32.         {
    33.             isActive = deksel.activeSelf;
    34.             deksel.SetActive(!isActive);
    35.             _rb.gravityScale = (isActive ? 1 : 0);
    36.         }
    37.     }
    38. }
     
  4. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    There is still not enough information to give useful feedback.

    You have a ball object, is it just an object in your scene, is it a prefab, does it get instantiated, is it a scriptable object?
    You have an ufo object, ... same questions
    What is supposed to happen when the ball hit the ufo's, or ufo's hit each other, or ufo hit the ball.
     
  5. SidCanGame

    SidCanGame

    Joined:
    Jul 19, 2023
    Posts:
    6
    Ok the ball is the player and I want the ufo to work when the player is in the ufo but the ufo works but if I copy paste the ufo the ufo will not work because the ufo instantiated to the ball so the script of the ball can use the ufo to turn the ufo on and off when the ball is in the ufo and I press q
     
    Last edited: Sep 6, 2023
  6. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    replace every "it" in your text, with what it actually is. Ball, ufo, script, and so on. Share your code. This is all still not making any sense.
     
  7. SidCanGame

    SidCanGame

    Joined:
    Jul 19, 2023
    Posts:
    6
    I changed it
     
  8. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    What exactly do you mean by copy paste? Did you create a prefab of the ufo?
     
  9. SidCanGame

    SidCanGame

    Joined:
    Jul 19, 2023
    Posts:
    6
    Yea I did make a prefab of it
     
  10. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    That is a great start. However, you are just not sharing enough information/code to grasp what you are exactly trying to do and what the exact current flow is. I can't help you any further without that.

    Maybe take a look at how other people supply information for their problem.
     
  11. Coding-Beast

    Coding-Beast

    Joined:
    Sep 8, 2021
    Posts:
    42
    Hey If your issue is still not solved contact me on discord
    My discord id: codingbeast
    if above one don't work try this one
    Muhammad Ali#9771

    Your information is not enough only way to solve your issue is to see it while hapening.