Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Search the Community

Showing results for tags 'instantiate'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • GENERAL
    • Introduce yourself
    • Discussions
    • Showcase
    • Need help?
    • Seeking team members?
    • Offtopic
  • RESOURCES
    • Example Projects
    • Scripts
    • Shaders
    • Unity Tutorials
    • FPS Kit Tutorials
    • 3D models
    • Animated 3D Models
    • Graphic design
    • Textures
    • Sounds
    • Other
  • SELL | REQUEST
    • Sell
    • Request
  • Mars' Modular Multiplayer Photon FPS Kit's Topics
  • Mars' Modular Multiplayer Photon FPS Kit's Reviews
  • Mars' Modular Multiplayer Photon FPS Kit's Updates
  • Mars' Modular Multiplayer Photon FPS Kit's Tutorials
  • Busy People's Introductions
  • Photon's Tutorials
  • Photon's Photon General
  • Photon's Showcase

Categories

  • Free Projects
  • Free Assets
  • Game Demos
  • Photon's Files

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


YouTube URL


Facebook URL


Twitter URL


IndieGoGo URL


Kickstarter URL


IndieDB URL


GreenLight URL


Location:


Interests

Found 6 results

  1. I'm sorry for my English. My Unity 2017.3.0f2 worked fine yesterday, but when I loaded my project today, it froze when I tried to create an instance of the object, identify the code that caused this error and I share it with you, I do not know what the problem was inside the code, it worked fine yesterday , I thought that the cycle produces this error, but I do not see anything wrong inside the code, please need help with my code, what I try is to capture all the Gameobjects in front of the object, and that they are saved in an array, to later use the position of these GameObject to instantiate a bomberman-style bomb, and check for hits.Length greater than zero. Here I leave the code already commented: void CaptureAllDelante(){ RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, Vector3.forward, Potencia); int i = 0; print ("Check if hits.length greater zero // " + hits.Length.ToString()); while (i < hits.Length) { if (hits [i].transform.tag == "Paredes" || hits [i].transform.tag == "Player" ) { break; //"if object tag is Paredes / Player, Stop while" } else if(hits [i].transform.tag == "Destructibles"){ //"if object tag is Destructibles , save object in array ObjetosDelante for use the position later" RaycastHit hit = hits[i]; ObjetosDelante [i] = hits [i].transform.gameObject; Debug.Log (hit.collider.gameObject.tag.ToString()); i++; } } for (int a = 0; a < ObjetosDelante.Length; a++) { if (ObjetosDelante[a] == null) { break; } //"if ObjetosDelante if != null instantiate Explosion in each position of object in array" Instantiate (Explosion, ObjetosDelante[a].transform.position,Quaternion.identity); } SearchObjetoDelante = false; }
  2. tomtomsumsum

    instantiate

    i want to instantiate a prefab at the point the player looks pls help me i need a script (I use C#)
  3. I made a script (C#) and want that my gameobject spawns at a random position near the object (tree)(radius of maximal 3) that gets destroyed how can i doo this ? HERE is the Scipt: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Treehealth : MonoBehaviour { public int health = 100; public GameObject logs; public GameObject conifer_tree; private void Update() { if (health <= 0) { Destroy(gameObject); Instantiate(logs, conifer_tree.transform.position, Quaternion.identity); Instantiate(logs, conifer_tree.transform.position, Quaternion.identity); Instantiate(logs, conifer_tree.transform.position, Quaternion.identity); Instantiate(logs, conifer_tree.transform.position, Quaternion.identity); Instantiate(logs, conifer_tree.transform.position, Quaternion.identity); } } } i saw a video but this was in javascript i hope anyone can help me
  4. public void OnJoinedRoom(){ t = GameObject.Find ("ground").GetComponent<Terrain> (); if (PhotonNetwork.isMasterClient) { //spawn_items (); for (int i =0; i < 1000; i ++) managenaturespawn(); } } public void managenaturespawn(){ if (PhotonNetwork.isMasterClient) { pos = mainpoint.transform.position + Random.insideUnitSphere * 440; pos.y = t.SampleHeight (pos); int chose = Random.Range (0, natureitems.Count); GetComponent<PhotonView>().RPC("universalspawn",PhotonTargets.AllBuffered,pos,chose); } } [PunRPC] public void universalspawn(Vector3 pos , int choice){ GameObject newitem = (GameObject)Instantiate ((GameObject)Resources.Load ("objects/" + natureitems [choice]), pos, Quaternion.identity); allthethings.Add (newitem); newitem.GetComponent<item_identification> ().id = allthethings.Count - 1; } Hello, so we are making an android game which requires the master client to instantiate about 1000 gameobjects and sync it with the clients.But the game gets stuck on android devices when a player joins the game. No issue occurs on PC however. Is there a better way to do this?
  5. I am making 2d game of cannon shooting.I take fruit item as a bullet.I make GUI in which different fruit items are present i.e. Apple ,Water melon , orange etc. I want to map each gui image to a prefab of the actual item so when the player , for example, clicks the apple then the apple prefab is instantiated as the bullet. This is my current script .... using UnityEngine; using System.Collections; public class TurretController : MonoBehaviour { private Vector3 mouse_pos; private Vector3 object_pos; private float angle; private float bulletSpeed = 450; public GameObject[] ammo; // Array of enemy prefabs. // Use this for initialization void Start () { } void Update(){ } void FixedUpdate () { // Point the cannon at the mouse. mouse_pos = Input.mousePosition; mouse_pos.z = 0.0f; //object_pos = Camera.main.WorldToScreenPoint(transform.position); mouse_pos.x = mouse_pos.x - object_pos.x; mouse_pos.y = mouse_pos.y - object_pos.y; angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg - 20; Vector3 rotationVector = new Vector3 (0, 0, angle); transform.rotation = Quaternion.Euler(rotationVector); // Fire a bullet. if(Input.GetMouseButtonDown(0)){ int ammoIndex = 0; GameObject bullet = (GameObject)Instantiate(ammo[ammoIndex], transform.position, transform.rotation); bullet.transform.LookAt(mouse_pos); bullet.rigidbody2D.AddForce(bullet.transform.forward * bulletSpeed); } } }
  6. So here's the deal, basically in my game i'm having a huge open world and am having the player spawn at a random spawnPoint, in the open world. But the thing is is that i'm using GameObject.FindGameObjectsWithTag to find the spawn points (them i'm adding them in a array) I'm having my player instantiate at one of the spawn point in the array, only thing is I keep getting this message: NullReferenceException: Object reference not set to an instance of an object Spawn Manager.Spawn () (at Assets/Spawn Manager.js:16) Spawn Manager.Start () (at Assets/Spawn Manager.js:8) I checked within the code and am very confused, i'm sill learning this stuff and to the people who really know this, this question probably sounds stupid. But I still can't find the problem that Unity is talking about, I have a very short and simple script. Here it is: var spawnPoints : GameObject[]; // Array for Player's spawn var PlayerPrefab : GameObject; // Player Prefab to spawn function Start(){ spawnPoints = GameObject.FindGameObjectsWithTag("PlayerSpawn"); Spawn(); } function Spawn(){ var obj : GameObject = PlayerPrefab; var pos: GameObject = spawnPoints[Random.Range(0, spawnPoints.length)]; // Randomize Spawn Points Instantiate(obj, pos.position, pos.rotation); } See? Not much. The SpawnPoints I currently have in-game are tagged with "PlayerSpawn" but I know that's not the issue. And I'm sure i'm being just stupid with the issue here and i'm also sure that there's a easy way around this but that's why i'm asking for help, (So I can learn this stuff and get better) If anyone can help me figure this out much would be appreciated. Thanks!
×
×
  • Create New...