C# (CSharp) GameObject Code Examples

C# (CSharp) GameObject - 30 examples found. These are the top rated real world C# (CSharp) examples of GameObject extracted from open source projects. You can rate examples to help us improve the quality of examples
	void OnDrop (GameObject go)
	{
		if (onDrop && target != null)
		{
			target.SendMessage("OnDrop", go, SendMessageOptions.DontRequireReceiver);
		}
	}
Example #2
0
    public void cellClicked(GameObject go)
    {
        MusicManager.playEffectMusic("SFX_UI_button_tap_2a");
        // if(selectedCell != go)
        // {
        selectedCell = go;
        SkillTreeCell cell = selectedCell.GetComponent<SkillTreeCell>();

        if (SkillLearnedData.LearnedState.LEARNED == cell.learnedData.State)
        {
        //			cell.IsSelected = true;
        //			cell.updateOutlook();
        //	 		changeHeroSkillList(cell);
        //			changeSkillTreeCellBortherState(cell);
        //			UserInfo.instance.saveAllheroes();
            selectSkill(cell);
        }
        descDlg.DescIcon.spriteName = cell.icon.spriteName;
        descDlg.DescIcon.gameObject.SetActive(true);
        descDlg.DescIconBg.spriteName = cell.frame.spriteName;
        descDlg.DescIconBg.MakePixelPerfect();
        descDlg.DescIconBg.gameObject.SetActive(true);
        descDlg.Show(cell.skillDef);
        descDlg.SetTrainingBtnVisible(SkillLearnedData.LearnedState.UNLEARNED == cell.learnedData.State);
        descDlg.SetSkippingBtnVisible(SkillLearnedData.LearnedState.LEARNING  == cell.learnedData.State);
        descDlg.skillTrainTimeMask.fillAmount = 0;
        cell.OnFinished = OnFinishedLearning;
    }
	private static void FindMissingReferences(string context, GameObject[] objects)
	{
		foreach (var go in objects)
		{
			var components = go.GetComponents<Component>();

			foreach (var c in components)
			{
				if (!c)
				{
					Debug.LogError("Missing Component in GO: " + FullPath(go), go);
					continue;
				}

				SerializedObject so = new SerializedObject(c);
				var sp = so.GetIterator();

				while (sp.NextVisible(true))
				{
					if (sp.propertyType == SerializedPropertyType.ObjectReference)
					{
						if (sp.objectReferenceValue == null
						    && sp.objectReferenceInstanceIDValue != 0)
						{
							ShowError(context, go, c.GetType().Name, ObjectNames.NicifyVariableName(sp.name));
						}
					}
				}
			}
		}
	}
 public void ItWillHaveTheGameObjectSet()
 {
     GameObject go = new GameObject();
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.gameObject, Is.SameAs(go));
 }
Example #5
0
	public void onPickupClock(GameObject go, bool tr) {
		Interactable inter = go.GetComponent<Interactable>();
		if(inter != null) {
			//TODO Start ticking sound
			inter.setPuzzleState("pickedUp");
		}
	}
Example #6
0
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");

        anim = GetComponent<Animator>();
        charControl = GetComponent<CharacterController>();
    }
Example #7
0
 public void OnMouseDown()
 {
     //pego a unidade selecionada atravez do controlador de jogo
     GameObject selecionado = gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().objetoSelecionado;
     //Se tiver algum objeto selecionado, mando a unidade selecionada se mover para o objeto clicado
     if(selecionado != null)
     {//Se tiver alguma unidade selecionada
         if(tropaJogador == null)
         {//E se nao tiver nem uma unidade nesse alvo (unidade do jogador)
             //Defino que tem uma unidade vindo pra ca
             tropaJogador = selecionado;
             //Se a unidade que esta vindo estiver vindo de um outro alvo, limpo o alvo antigo
             if(tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual != null)
                 tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual.GetComponent<AcoesJogadorAlvo>().tropaJogador = null;
             //Mando a unidade se mover para o alvo atual
             tropaJogador.GetComponent<ComportamentoDeUnidade>().moverSoldados(gameObject);
             //E digo que esse alvo e o novo destino dele
             tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual = gameObject;
             //atualizar as cores do alvo
             atualizarCores();
         }
         else
             gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().hud.GetComponent<ControladorDeInterface>().escreverMensagem("Nao pode haver dois grupos em um mesmo alvo");
     }
 }
Example #8
0
 private static void OnCreate(GameObject sender, EventArgs args)
 {
     if (sender.Name.Contains("healingBuff"))
     {
         _healingBuffs.Add(sender);
     }
 }
    public void updateAllBuildings()
    {
        // Ottengo il numero di costruzioni sulla cella
        GameManager gMgr = GameObject.Find("GameManager").GetComponent<GameManager>();
        // Ciclo su tutte le mini-celle della board principale
        for (int i = 0; i < 40; i++) {
            // Ottengo la cella corrente
            GameObject curCell = GameObject.FindGameObjectWithTag(i.ToString());
            try {
                // Ottengo il set di case incluse nella cella
                GameObject curSet = curCell.transform.Find("GlobalBuildings").gameObject;
                GameObject[] curBuildings = new GameObject[5];

                // Nascondo prima tutte le costruzioni
                for (int houseIndex = 0; houseIndex < 5; houseIndex++) {
                    // trovo la componente che ci serve
                    curBuildings[houseIndex] = curSet.transform.Find("b" + (houseIndex+1).ToString()).gameObject;
                    curBuildings[houseIndex].SetActiveRecursively(false);
                }

                int mBuildings = 0;
                try {
                    mBuildings = gMgr.Cells[i].getProperty().getNumberOfBuildings();
                } catch (ArgumentOutOfRangeException e) {
                    mBuildings = 0;
                }

                if (mBuildings > 0) {
                    // Aggiorno i valori della cella
                    setBuildings(mBuildings, curBuildings);
                }
            } catch (NullReferenceException e) {
            }
        }
    }
Example #10
0
    //指定されたタグの中で最も近いものを取得
    GameObject serchTag(GameObject nowObj,string tagName)
    {
        float tmpDis = 0;           //距離用一時変数
        float nearDis = 0;          //最も近いオブジェクトの距離
        //string nearObjName = "";    //オブジェクト名称
        GameObject targetObj = null; //オブジェクト

        //タグ指定されたオブジェクトを配列で取得する
        foreach (GameObject obs in  GameObject.FindGameObjectsWithTag(tagName)){
            //自身と取得したオブジェクトの距離を取得
            tmpDis = Vector3.Distance(obs.transform.position, nowObj.transform.position);

            //オブジェクトの距離が近いか、距離0であればオブジェクト名を取得
            //一時変数に距離を格納
            if (nearDis == 0 || nearDis > tmpDis){
                nearDis = tmpDis;
                //nearObjName = obs.name;
                targetObj = obs;
            }

        }
        //最も近かったオブジェクトを返す
        //return GameObject.Find(nearObjName);
        return targetObj;
    }
	// Use this for initialization
	void Awake () 
    {
        player = GameObject.FindGameObjectWithTag("Player");
        playerControl = player.GetComponent<playerControl>();
        som = gameObject.GetComponent<AudioSource>();
        bala = gameObject.GetComponent<MeshRenderer>();
	}
	static public GameObject target; // the target that the camera should look at

	void Start () {
		if (target == null) 
		{
			target = this.gameObject;
			Debug.Log ("LookAtTarget target not specified. Defaulting to parent GameObject");
		}
	}
    public void LoadResourceInsteadOfAwake()
    {
        if (m_bLoadResourceInsteadOfAwake)
            return;

        m_bLoadResourceInsteadOfAwake = true;

        m_myTransform = transform;
        FillFullNameData(m_myTransform);

        m_goFingerTailUIDrawRange = FindTransform("FingerTailUIDrawRange").gameObject;

        m_goFingerTailUIDrawPanel = FindTransform("FingerTailUIDrawPanel").gameObject;
        DontDestroyOnLoad(m_goFingerTailUIDrawPanel);
        ShowFingerTailUIDrawPanel(false);
        m_goFingerTailUIDrawPanel.transform.parent = null;
        m_goFingerTailUIDrawPanel.transform.localPosition = Vector3.zero;
        m_goFingerTailUIDrawPanel.transform.localScale = new Vector3(1, 1, 1);

        m_MFUIFingerTail = m_goFingerTailUIDrawRange.AddComponent<MFUIFingerTail>();
        m_MFUIFingerTail.UICamera = GameObject.Find("Camera").GetComponentsInChildren<Camera>(true)[0];
        m_MFUIFingerTail.GoTail = m_goFingerTailUIDrawPanel;
        m_MFUIFingerTail.TailWidth = 20;
        m_MFUIFingerTail.LoadResourceInsteadOfAwake();
    }
Example #14
0
    public static void SavePanelChildren( GameObject savedObj , ref List<SceneData.SceneNodeData> nodelist , ref ISpriteFactory spriteFact )
    {
        nodelist.Clear();

        // savedObj <== named "SavedLayer" GameObject and this is not serialized.
        int count = savedObj.transform.GetChildCount();
        if( count > 0 ){
            for(int i=0;i<count;i++){
                GameObject childObj =  savedObj.transform.GetChild( i ).gameObject;
                SaveDataRecursively( childObj ,ref nodelist , ref spriteFact );
            }
        }

        // TEST . TEXT BOX POSITION SAVE.
        /*
        SceneData.SceneNodeData dat = new SceneData.SceneNodeData();
        GameObject _TEXTBOX = GameObject.Find( "TextBox" );
        if( _TEXTBOX != null ){
            dat.nodeType = SceneNodeType.NODE;
            nodelist.Add( dat );
            spriteFact.SaveData( ref dat , _TEXTBOX );
        }
        else{
            ViNoDebugger.LogError( "TextBox Not Found !" );
        }
        //*/
    }
Example #15
0
 // Use this for initialization
 void Start()
 {
     GlobalValues.statePc = pcMovement;
     timeSpent = 1.0f;
     camera = GameObject.Find ("Main Camera");
     meatballPlane = GameObject.Find ("Meatball Plane");
 }
Example #16
0
    protected void Spawn_Diamond(GameObject Tile, float Movement)
    {
        Spawn_Tile (Tile, Vector2.zero);
        for (int i = 0; i <= Movement; i++)
         		{
            Vector2 Spawn_Position = Vector.Up * i;
            for (int iSpawn = 0; iSpawn < i; iSpawn++)
            {
                Spawn_Position += Vector.Right;
                Spawn_Position += Vector.Down;
                Spawn_Tile(Tile, Spawn_Position);
            }

            for (int iSpawn = 0; iSpawn < i; iSpawn++)
            {
                Spawn_Position += Vector.Down;
                Spawn_Position += Vector.Left;
                Spawn_Tile(Tile, Spawn_Position);
            }

            for (int iSpawn = 0; iSpawn < i; iSpawn++)
            {
                Spawn_Position += Vector.Left;
                Spawn_Position += Vector.Up;
                Spawn_Tile(Tile, Spawn_Position);
            }

            for (int iSpawn = 0; iSpawn < i; iSpawn++)
            {
                Spawn_Position += Vector.Up;
                Spawn_Position += Vector.Right;
                Spawn_Tile(Tile, Spawn_Position);
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        //for the comp time leaderboard
        CompTimeColum1 = GameObject.Find ("CompTimeRow1");
        CompTimeColum2 = GameObject.Find ("CompTimeRow2");
        CompTimeColum3 = GameObject.Find ("CompTimeRow3");
        CompTimeLine2 = GameObject.Find ("CompTimeLine2");

        //for the enemies killed leaderboard
        EnemieskilledColum1 = GameObject.Find ("EnemiesKilledRow1");
        EnemieskilledColum2 = GameObject.Find ("EnemiesKilledRow2");
        EnemieskilledColum3 = GameObject.Find ("EnemiesKilledRow3");
        EnemieskilledLine2 = GameObject.Find ("EnemiesKilledLine2");

        //for the least damage leaderboard
        LeastDamageColum1 = GameObject.Find ("LeastDamageRow1");
        LeastDamageColum2 = GameObject.Find ("LeastDamageRow2");
        LeastDamageColum3 = GameObject.Find ("LeastDamageRow3");
        LeastDamageLine2 = GameObject.Find ("LeastDamageLine2");

        ReadFile.Load ("Assets/Data Files/Leaderboard.txt"); // the file that is loaded

        CompletionTime ();
        EnemiesKilled ();
        LeastDamage ();

        //not needed on the leaderboard for the main menu, but will be needed when accessed from the end of game
        CompTimeLine2.SetActive (false);
        EnemieskilledLine2.SetActive (false);
        LeastDamageLine2.SetActive (false);
    }
Example #18
0
 private void Spawn_Tile(GameObject Select_Tile, Vector2 Position)
 {
     GameObject Tile = Instantiate (Select_Tile);
     Tile.transform.parent = transform;
     Tile.transform.position = transform.position;
     Tile.transform.position += (Vector3)Position;
 }
Example #19
0
    public CharaController(CharaConfiguration chara, Configuration config, GameObject[] objs, bool debug = false)
    {
        _chara = chara;
        _config = config;

        _objs = objs;
        _joints = new ConfigurableJoint[_objs.Length];
        _rigs = new Rigidbody[_objs.Length];
        _init_rot = new Quaternion[_objs.Length];
        _target_rot = new Quaternion[_objs.Length];
        _target_pos = new Vector3[_objs.Length];

        _debug = debug;

        for (int i = 0; i < _objs.Length; ++i) {
            _rigs[i] = _objs[i].GetComponent<Rigidbody>();
            /*
            if (_debug)
                _rigs[i].isKinematic = true;
                */
            _init_rot[i] = _objs[i].transform.localRotation;
            _target_rot[i] = _init_rot[i];

            _joints[i] = _objs[i].GetComponent<ConfigurableJoint>();
        }

        InitializeJoints();
    }
 private void Move(GameObject prefab)
 {
     //move object upwards over time * speed
     Vector2 pos = prefab.GetComponent<RectTransform>().anchoredPosition;
     pos.y += 1 * speed * Time.deltaTime;
     prefab.GetComponent<RectTransform>().anchoredPosition = pos;
 }
 public void ItWillBeSetToBeAPrefabIfTheGameObjectIsAPRefab()
 {
     GameObject go = new GameObject() { isPrefab = true };
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.isPrefab, Is.EqualTo(go.isPrefab));
 }
Example #22
0
    void OnGUI()
    {
        if(!Network.isClient && !Network.isServer) {
            if(!bNodeSelected) {
                for(int i=0; i<length; i++) {
                    if(GUI.Button(new Rect(10, 300+i*30, 200, 30), "Node: "+i.ToString()+"  Type: "+nodeTypes[i].ToString())) {
                        selNode=i;
                        selNodeType=nodeTypes[i];
                        bNodeSelected=true;

                        highlight = Instantiate(highlightObject, nodes[i].transform.position, nodes[i].transform.rotation) as GameObject;
                    }
                }
            } else {
                for(int i=0; i<wepAmnt; i++) {
                    if(weaponObject.GetComponent<wepProperties>().weapons[i].nodeType == selNodeType) {
                        if(GUI.Button(new Rect(10, 300+i*30, 200, 30),  GetComponent<wepProperties>().weapons[i].name)){
                            wepLocs[selNode]=i;
                            updateNodes(selNode, i);
                            bNodeSelected=false;
                            Destroy(highlight);
                        }
                    }
                }
            }
            /*for(int i =0; i<wepLocs.Length; i++) {
                GUI.Label(new Rect(15, 500+i*30,300,30), wepLocs[i].ToString());
            }*/
        }
    }
 public void WeCanDoItWithJustItsType()
 {
     GameObject go = new GameObject();
     Component comp = go.AddComponent(typeof(TestComponent));
     Assert.That(comp, Is.Not.Null);
     Assert.That(comp.gameObject, Is.SameAs(go));
 }
    protected void OnCollisionWithEnemy(GameObject enemy, float power)
    {
        power *= WeaponPowerMiltiplier;
        enemyTransform = enemy.transform;
        enemyController = enemy.GetComponent<FightEnemyController>();

        if (power < MinForceToHit)
            return;

        // Blood
        newBloodParticle = Instantiate<GameObject>(BloodParticles);
        newBloodParticle.transform.position = enemyTransform.position;
        newBloodParticle.transform.up = (enemyTransform.position - selfTransform.position).normalized;
        Destroy(newBloodParticle, 1);

        // Do damage
        enemyController.DoDamage(Mathf.Clamp(power, MinForceToHit, MaxForceToHit));
        //print(WeaponTypeName + ": " + hitVelocityMagnitude.ToString());

        // Damage Text
        newDamageText = Instantiate<GameObject>(DamageText);
        newDamageTextText = newDamageText.GetComponent<Text>();
        newDamageTextText.rectTransform.SetParent(WorldCanvas, false);
        newDamageTextText.rectTransform.position = enemyTransform.position + new Vector3(0f, 0.5f, 0f); ;
        newDamageTextText.text = string.Format("{0}", power.ToString("F0"));
    }
 private GameObject AddBGLayer(GameObject layer)
 {
     GameObject newBackground = ObjectPooler.instance.GetObjectByName(layer.name, true);
     newBackground.GetComponent<ParallaxLayer>().setLastGenerated(true);
     AddLayerToList(newBackground.GetComponent<ParallaxLayer>());
     return newBackground;
 }
Example #26
0
	public void Open(GameObject goRoot, int nTimeDurationSec)
	{
		gameObject.SetActiveRecursively( true);
		m_goRoot = goRoot;
		
		_StartTime( nTimeDurationSec);
	}
Example #27
0
    public static void expect( bool didPass, string definition, string failExplaination = null)
    {
        float len = printOutLength(definition);
        int paddingLen = 40-(int)(len*1.05f);
        #if UNITY_FLASH
        string padding = padRight(paddingLen);
        #else
        string padding = "".PadRight(paddingLen,"_"[0]);
        #endif
        string logName = formatB(definition) +" " + padding + " [ "+ (didPass ? formatC("pass","green") : formatC("fail","red")) +" ]";
        if(didPass==false && failExplaination!=null)
            logName += " - " + failExplaination;
        Debug.Log(logName);
        if(didPass)
            passes++;
        tests++;

        // Debug.Log("tests:"+tests+" expected:"+expected);
        if(tests==expected && testsFinished==false){
            overview();
        }else if(tests>expected){
            Debug.Log(formatB("Too many tests for a final report!") + " set LeanTest.expected = "+tests);
        }

        if(timeoutStarted==false){
            timeoutStarted = true;
            GameObject tester = new GameObject();
            tester.name = "~LeanTest";
            LeanTester test = tester.AddComponent(typeof(LeanTester)) as LeanTester;
            test.timeout = timeout;
            #if !UNITY_EDITOR
            tester.hideFlags = HideFlags.HideAndDontSave;
            #endif
        }
    }
Example #28
0
 //public string objectNarration;
 // Use this for initialization
 void Start()
 {
     playerCamera = GameObject.Find("First Person Controller/Main Camera");
     objectNarration = GameObject.Find("Object Narration");
     objectNarrationGUI = objectNarration.GetComponent<GUIText>();
     objectNarrationGUI.enabled = false;
 }
 public void AfterInstantiatingANewObjectItExists()
 {
     Assert.Inconclusive("I am not sure if this is the correct behaviour...");
     GameObject obj = new GameObject();
     GameObject clone = (GameObject)GameObject.Instantiate(obj);
     Assert.That(Application.Find(clone.GetInstanceID()), Is.Not.Null);
 }
Example #30
0
 void OnGUI()
 {
     GUILayout.Box("Legacy Effect Scale Editor", GUILayout.Width(295));
     EditorGUILayout.Space();
     Effect = (GameObject)EditorGUILayout.ObjectField("Legacy Effect", Effect, typeof(GameObject), true); 
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     Scale = float.Parse(EditorGUILayout.TextField("Scale Change Value", Scale.ToString()));
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     if (GUILayout.Button("Scale Apply", GUILayout.Height(70))) 
     {
         if (Effect.GetComponent<csLegacyEffectChanger>() != null)
             Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
         else
         {
             Effect.AddComponent<csLegacyEffectChanger>();
             Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
         }
         DestroyImmediate(Effect.GetComponent<csLegacyEffectChanger>());
     }
 }