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. Dismiss Notice

sliders

Discussion in 'Scripting' started by gagac42, Sep 3, 2018.

  1. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    Dobrý deň, mám problém s viacerými jazdcami v scéne a píšem skript jeden objekt, ale môj skript nenašiel jazdci pomôžte mi pls
    tu je skript, ale nefunguje
    posuvník = GameObject.FindGameObjectWithTag ("Posuvné") GetComponent <Posuvník> ();
    Code (CSharp):
    1.   slider[i] = GameObject.FindGameObjectWithTag("Sliders").GetComponent<Slider>();
     
    Last edited: Sep 3, 2018
  2. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    Two things : Do the objects with sliders have the tag "Sliders" on them EXACTLY? Do the objects with the tags "Sliders" on them exactly, have sliders on them?

    Prove that the answer is yes to both of these questions with pictures.
     
  3. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
  4. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    You've changed your original code. Is your array initialized? Rather than play twenty questions please provide more information such as the pictures I requested. If you want people on the forum to put in effort to help you, show that you're willing top put in effort to get help.

    For all I know, your code could be returning, or throwing exceptions before that line of code. You could have missed a character in the tag, you could be retrieving it correctly but not referencing the variable caching it correctly.
     
  5. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    here is my script

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Sliders : MonoBehaviour {
    7.     public Slider[] slider;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.        
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update () {
    16.  
    17.         SkinnedMeshRenderer body = GetComponent<SkinnedMeshRenderer>();
    18.         Mesh m = body.sharedMesh;
    19.         for (int i = 0; i < m.blendShapeCount; i++)
    20.         {
    21.             slider = new Slider[m.blendShapeCount];
    22.             slider[i] = GameObject.FindGameObjectWithTag("Sliders").GetComponent<Slider>();
    23.     }
    24. }
    25. }
    26.  
     
  6. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    script loaded only size sliders not sliders :(
     
  7. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    you really shouldn't be running that code in the update loop, unless the components change that often, move it to the start method. Even if they did change that often I would argue that's a design problem/flaw and you should definitely being trying to solve your problem a different way.