Does anybody know where to find any good candy crush or bejeweled tutorials for unity are? I have been looking for a while and cant seem to find any good tutorials. I do not wish to purchase any packages from the asset store.
↧
Candy Crush tutorial
↧
Random ball generator?
Hello,
I need help creating a game. I want to have a character on the bottom of the screen of my 2D game, and I want balls to be spawned randomly from the left and right walls. Now, everything is good so far, however I do not have any idea how to clone my already existing balls objects,randomly on the edge of the screen(right or left).
Any help?
Thank you!
↧
↧
Can I duplicate folder with internal dependencies between objects?
Hi guys!
I have a folder with some prefabs, materials, textures and etc. Prefabs refers to textures in this folder.
Can I clone this folder with saving local dependencies?
For example:
Folder is named "Assets/BaseFolder". And prefab "Assets/BaseFolder/preFab" refers to "Assets/BaseFolder/texture".
I need to Copy "Assets/BaseFolder" to "Assets/CloneFolder", so that "Assets/CloneFolder/preFab" refer to "Assets/CloneFolder/texture".
By default, when I dublicate folder - dependencies refers to the old resources with old paths.
I can do it manually in editor for every object. But I have many objects and many dependencies, and I need to automate this process.
Does anyone have any ideas?
Thanks for any answer,
Vlad
↧
Destroy one prefab clone of set of clones.
To be more specific, is there a way to destroy a certain clone from a list of clones?
My problem is that I have 5 HousePrefab(Clone)s in my scene, I placed them using raycast, say I only wanted 4 and I built too many. Using this code deletes the first once built which is not what I want, I'd like to delete the one my mouse is over.
if (Input.GetButtonDown ("Fire1") && collider.Raycast (ray, out hitInfo, Mathf.Infinity) && KeepingScore1.Selected == 4) {
Destroy(GameObject.Find("House(Clone)"));
}
// KeepingScore.Selected == 4 is a reference to my 'remove' button being active.
I'm a bit stuck because I'm not sure if I can use Raycast to solve my issue. Or whether I need to make an array of gameObjects or if attaching a script to the HousePrefab would do it. Any advice on the way forward would be greatly helpful.
↧
Script finding a none-existing player clone
Hi!
I am making a simple player follow script and it is not working. When I checked what it is finding, it is finding "Player(Clone)". There is no clone in the scene or in the prefabs. Why is it doing this?
My code.
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public GameObject target;
void Start(){
target = GameObject.FindGameObjectWithTag("Player");
}
void Update(){
transform.position = new Vector3(target.transform.position.x, target.transform.position.y, -10);
}
}
↧
↧
How to have a mini camera of my scene
Hi, i want to know if is possible to have a cloned reduced view of my main camera in another camera positioned in a small box in left bottom corner of my scene.
How could i clone the main camera view in a smaller camera on the stage?
Thanks in advance for the help
↧
Cloned Object does not run Scripts
Good day for all.
Well, My point is: I have created a simple GameObject which has a Renderer with a Single Sprite.
No Animations, no magics, not fancy... OK.
Secondly, i´ve created a C# Script. The most simple C# Scripts ever seen:
I have a void update method which print("hello world").
OK, so now a dragged that GameObject to my Project, so it becomes a "Prefab", right?
In parallel, i´ve create an ObjectPool Script, so i can Instantiate 20 clones of my Prefabs in its start method. OK?
So, I attach this ObjectPool Script to an empty GameObject and associate my prefab as the type to be pooled.
Here i have the premisse: 1 empty GameObject which has a script to pool GameObjects which has my "Simple Prefab", which contains a Script which prints "hello world".
I play my "game", what i can see that all of the clones are created in hierarquy but none of them runs my print("Hello World") unless for the original prefab.
It seems that the Instantiate method is not cloning my whole prefab.
Does anyone have idea about the why my Clone´s Scripts are not running? In addition: does inactive objects are still able to run their scripts??
Att,
Marcello
↧
Script cannot find component after mecanim change
Hey all, weird one here.
I have a player prefab, just canabalized some code to make a simple movement function. It worked fine, player moved as expected. I was playing with mecanim transitions, specifically Idle -> Movement when, after hitting play, I get the following error;
MissingComponentException: There is no 'Rigidbody' attached to the "Player(Clone)" game object, but a script is trying to access it.
You probably need to add a Rigidbody to the game object "Player(Clone)". Or your script needs to check if the component is attached before using it.
UnityEngine.Rigidbody.get_rotation () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/NewDynamics.cs:907)
Player_Movement.Player_Rotation () (at Assets/Prefabs/Player/Player_Movement.cs:75)
Player_Movement.Movement_Manager () (at Assets/Prefabs/Player/Player_Movement.cs:52)
Player_Movement.FixedUpdate () (at Assets/Prefabs/Player/Player_Movement.cs:37)
I did no modification whatsoever to the code. It went from working fine to not working at all with a simple Mecanim exit time change. All scripts were saved, I assure you, nothing changed but an exit time on a transition.
Hoping this is a known bug. Using Unity 4.6 Beta, so that may be it. In any case, any help would be great! Last time this happened I had to create a whole new project, reimport assets, and remake all the scripts.
Also, if anyone knows why it now says "Clone" after my prefab, would appreciate it!
Thanks.
↧
Prefab clone not working
Hi everyone,
Im very new to unity and I am trying to create 5 of the same game object using a prefab but for some reason it does not work. (http://docs.unity3d.com/Manual/InstantiatingPrefabs.html iv been using this)
I have done all of the instructions (create cube, add rigidbody and drag it into the prefab) and the code in the script is as followed
using UnityEngine;
using System.Collections;
public class multiboxes : MonoBehaviour {
public Rigidbody boxR;
// Use this for initialization
void Start ()
{
for (int i = 0; i < 5; i++)
{
Vector3 position = new Vector3 (Random.Range (-3.0f, 3.0f), Random.Range (-2.0f, 2.0f), -2.0f);
Rigidbody boxclone = (Rigidbody)Instantiate (boxR, position, Quaternion.identity);
}
}
// Update is called once per frame
void Update ()
{
}
}
I have also made sure that I dragged the prefab into the BoxR rigidbody.
![alt text][1]
Any help will be very appreciated.
[1]: /storage/temp/34725-prefab+data.png
↧
↧
GameObject size center of the screen
I'm downloading 3d model dynamically using Obj Reader and displaying in the scene but sometimes model showing too small and too big. I can't place in center of the screen for all the model. How to do this?
// duplicate the referenced image target
newImageTarget3d = Instantiate (ImageTargetTemplate3Dload.gameObject) as GameObject;
// enable the new result with the same ImageTargetBehaviour: ???
ImageTracker tracker = TrackerManager.Instance.GetTracker ();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)tracker.TargetFinder.EnableTracking
(targetSearchResult, newImageTarget3d);
StartCoroutine (seperateJsonLoad3D (mTargetMetadata, targetSearchResult.UniqueTargetId , imageTargetBehaviour ));
Obj Reader Library to get the model from server url:
IEnumerator seperateJsonLoad3D ( string jsonURL, string targetID, ImageTargetBehaviour itb ){
WWW www = new WWW (jsonURL);
yield return www;
jsonText = www.text;
Debug.Log("3D Url load is "+ jsonURL);
JSONObject json = JSONObject.Parse(jsonURL);
type=json.GetString("type");
url=json.GetString("link");
modelShowGUIButton=true;
if(type.Equals("3d")){
modal = GameObject.Find (targetID);
if (!modal) { //fetch model from the URL
Debug.Log("3D !modal is "+ url);
loadingText = (GUIText)GameObject.Find ("LoadingText").GetComponent(typeof(GUIText));
// loadingText = GameObject.Find("LoadingText").GetComponent(GUIText);
loadingText.enabled = true;
var objData = ObjReader.use.ConvertFileAsync (url , true);
while (!objData.isDone) {
loadingText.text = "Loading... " + (objData.progress*100).ToString("f0") + "%";
yield return null;
}
loadingText.enabled = false;
string modelName = objData.gameObjects[0].name;
modal = GameObject.Find (modelName); // find the model reference
modal.name = targetID; // change the model name to targetID !!!
// store the original model somewhere safe!!
modal.transform.position = new Vector3 (modal.transform.position.x, 500f, modal.transform.position.z);
}
modalClone = Instantiate( modal ) as GameObject; //clone the model
modalClone.transform.localScale += new Vector3(250,250,250);
/modalClone.AddComponent(MeshCollider);
mesh = modalClone.AddComponent();
modalClone.transform.parent = itb.gameObject.transform; // pair the clone to the instantiated image target
modalClone.transform.localPosition = new Vector3(0,0,0);
}
}
![alt text][1]
![alt text][2]
[1]: /storage/temp/34932-3d_destroy.jpg
[2]: /storage/temp/34933-3dship.jpg
↧
Clones AddForce individual
Hello! I spawn enemie's balls from spawn scrip and I want to move every ball to different direction, but when I'm using rigidbody2D.AddForce for clones, the are moving the same direction whith every added force. It's not individual, but summarized. How to make AddForce different for every clone?
GameObject clone1 = (Instantiate(FireBull, gameObject.transform.position, camera.transform.rotation) as GameObject);
clone1.rigidbody2D.AddForce(new Vector2(3000,0),ForceMode2D.Impulse);
GameObject clone2 = (Instantiate(FireBull, gameObject.transform.position, camera.transform.rotation) as GameObject);
clone2.rigidbody2D.AddForce(new Vector2(-3000,0),ForceMode2D.Impulse);
GameObject clone3 = (Instantiate(FireBull, gameObject.transform.position, camera.transform.rotation) as GameObject);
clone3.rigidbody2D.AddForce(new Vector2(0,1000),ForceMode2D.Impulse);
↧
Moving a transform behaves odd
Working on a 2D game.
So I have a Unit object prefab. The unit has a child object with a GUITexture (it's health bar)
I move the health bar guitexture if the unit moves like so:
public void LateUpdate () {
// if(!isSelected)
// return;
_lbl.SetActive(isSelected);
_pos = Camera.main.WorldToViewportPoint(transform.position);
_pos.z = 0f;
_pos.y = _pos.y+0.05f;
_lbl.transform.position = _pos;
}
The _lbl is the child object that contains the health bar.
When it was just a single object in the scene this worked perfectly. But whenever I instantiate a unit on runtime the health bar moves all jittery. Even if I drag a new object in the scene and save the scene the new object has the jitter. If i close unity and restart it and start the scene the new unit's health bar moves smooth again.
Since all units need to be dynamically instantiated this is a problem.
So to summarize:
Original object works like a charm, Object (clone) has weird jitter.
Any help with this conundrum would be greatly appreciated!
↧
transform.position assign attempt for 'Cubie' is not valid. Input position is { NaN, NaN, NaN }.
![alt text][1]
So here's some background information, I am trying to create this explosion effect of "cubie's". I have one object called enemy that when he collides with a bullet it destroys itself and instantiates another object called EnemyDeathAnimation which is not really an animation but a gameObject that replicates an explosion effect based on this tutorial: http://gamedevelopment.tutsplus.com/tutorials/how-to-make-an-object-shatter-into-smaller-fragments-in-unity--gamedev-11795
when I play the game and shoot the enemies occasionally I get the NaN error. I think it may be caused by the sphere used in the explosion effect instantiating and interfering with other objects. If anyone could shed some light on how to avoid/fix the error that would be great. If there is any better way of creating the explosion effect I would be more than happy to scratch this method and do it that way.
Enemy Script:
using UnityEngine;
using System.Collections;
public class EnemyCubeScript : MonoBehaviour
{
public GameObject deathAnimation;
private float fadeTimer = 1.9f;
private Transform player;
private NavMeshAgent nav;
void OnTriggerEnter (Collider col)
{
if(col.tag == "Bullet")
{
GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
Destroy (gameObject); //destroy self
Destroy (deathAnimationClone, fadeTimer);
Destroy (col.gameObject); //destroy bullet
}
}
void Awake () {
player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent ();
}
void Update () {
nav.SetDestination (player.position);
}
}
[1]: /storage/temp/36013-nan+error.png
↧
↧
Access terrain alphamaps directly? To clone them?
How do you clone a terrain's alphamap? It's inaccessible according to unity intellisense?
In case anyone reading this doesn't understand: setalphamaps() changes all clones of the terrain. Not just the terrain you use it on.
**The Solution:** Clone the alpha map.
**The Problem:** Can't access the alpha map's Texture2D object.
Hence this question being here.
↧
Destroy One Child, Not All
I have three Scripts
Script One
Game Manager:
SIMPLY(Guitar Hero Like Game)
4 Tubes, 4 Spawnners and 4 receivers
Each tube has an Inactive atom parent over the Spawnners which has a variable spawnner and receiver each assigned according to their position. So Parent 1 is assigned receiver 1 and spawnner 1 through inspector, atom parent 2 is assigned receiver 2 spanner 2 etc.
So...
Script 1 Game Manager (Outside of everything, randomly picks a spawnner and instantiates the atom parents( all 4 atom parents spawnners and receivers are in a list)
GameObject atom1_child = Instantiate(atomReference[0], atomSpawnners[0].transform.position, atomSpawnners[0].transform.rotation) as GameObject;
----------------
Script Two
attached to the child gameObject(atoms)
when it spawns... and collides, in my case gets within distance with the base or what I call the receiver...
buttonOccupied = true; // Has a boolean to make sure atom is inside receiever
receiver.GetComponent().SA_Atom = gameObject; //Script 3 in receiver
//Script 3 is a controller with the variable SA_Atom
So when this object is at a certain distance from base or ITS receiver, it self assigns itself to script 3.
--------------
Script 3
When I ray cast to a specific receiver
if (hit.collider.gameObject && SA_Atom.GetComponent().buttonOccupied == true)
//If I hit the receiever...
{
Destroy(SA_Atom);
}
----------------------
Heres the issue, ALL atom childs are being destroyed not just one. I tried several solutions, I cant wrap my head around it
ALSO, it doesnt destroy all atomChilds when the boolean is false, but when boolean is true and I click the receiver, it destroys all. I need it to be that ONE Specific Self assigned atom
HERES THE CODE
//Script ONE outside of anything
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class script_GameManager : MonoBehaviour
{
public GameObject[] atomReference = new GameObject[4];
private float spawnTimer;
public float setTimer;
public GameObject[] atomSpawnners = new GameObject[4];
private int randomSpawnnner;
void Start()
{
spawnTimer = setTimer;
}
void Update ()
{
timerUpdate();
}
void timerUpdate()
{
spawnTimer -= Time.deltaTime;
if(spawnTimer <= 0)
{
spawnTimer = setTimer;
randomSpawnnner = Random.Range(0, 4);
atomSpawn();
}
}
void atomSpawn()
{
switch (randomSpawnnner)
{
case 0:
GameObject atom1_child = Instantiate(atomReference[0], atomSpawnners[0].transform.position, atomSpawnners[0].transform.rotation) as GameObject;
atom1_child.SetActive (true);
break;
case 1:
GameObject atom2_child = Instantiate(atomReference[1], atomSpawnners[1].transform.position, atomSpawnners[1].transform.rotation) as GameObject;
atom2_child.SetActive (true);
break;
case 2:
GameObject atom3_child = Instantiate(atomReference[2], atomSpawnners[2].transform.position, atomSpawnners[2].transform.rotation) as GameObject;
atom3_child.SetActive (true);
break;
case 3:
GameObject atom4_child = Instantiate(atomReference[3], atomSpawnners[3].transform.position, atomSpawnners[3].transform.rotation) as GameObject;
atom4_child.SetActive (true);
break;
}
}
}
-------------------
//Script 2 inside parents or atoms
using UnityEngine;
using System.Collections;
public class script_Atom : MonoBehaviour {
public Transform receiver;
private float receiverDistance;
public float atomSpeed;
private Transform targetReceiver;
public GameObject buttonParticle;
public bool buttonOccupied = false;
void Update()
{
//---- atom positionining and particle activation ----
targetReceiver = receiver.transform;
//easy reference to the vector 3 conversion of the receiver
receiverDistance = Vector3.Distance(transform.position, targetReceiver.transform.position);
//converts the vector 3 (x,y,z) distance into a float
if(receiverDistance > 0.1)
{
atomMove();
//atom will move if far from the zero, otherwise, stop
}//EO IF
if (receiverDistance <= 0.1 && receiverDistance >= -0.1)
{
buttonOccupied = true;
//button is inside receiver
this.receiver.GetComponent().SA_Atom = gameObject;
buttonParticle.SetActive(true);
//if atom is close to zero, activate particle system, other wise will be shut off by controller
//a new spawning atom may overrde it being true to false even if the "zero" is occupied
}
}
void atomMove()
{
transform.Translate(Vector3.down * atomSpeed * Time.deltaTime);
}
public void atomSend()
{
//Destroy(gameObject);
}
}
------------------------
//script 3, attached to receivers
using UnityEngine;
using System.Collections;
public class script_buttonController : MonoBehaviour
{
RaycastHit hit;
public GameObject SA_Atom;
void Update()
{
if (SA_Atom)
{
}
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//sets up ray cast to camera for controller
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, out hit, Mathf.Infinity))
{
if (SA_Atom)
{
if (hit.collider.gameObject && SA_Atom.GetComponent().buttonOccupied == true)
{
SA_Atom.GetComponent().buttonParticle.SetActive(false);
Destroy(SA_Atom);
}
}
else if(SA_Atom == null)
{
//Do Nothing, receive no errors, AFTER Destroyed Gets a NULL ERROR
}
}
}
}
}
↧
Destroy instance clone of gameobject
I am creating a small interaction where you click on a table and a small animation plays in response. What I'm getting caught up on is that when I instantiate the click I cannot rid the click object from the game. This has ended up with me bogging it down with too many objects in scene. if you guys could take a look at my code I would greatly appreciate it! As I have been looking to the answer to this problem for hours now haha!
the fist block of code is in java script and the second is in c#
#pragma strict
var touch : GameObject;
function OnCollisionEnter (other : Collision) {
//public float initializationTime;
if (other.transform != transform && other.contacts.length!=0)
{
for (var i = 0; i < other.contacts.length; i++)
{
Instantiate(touch, other.contacts[i]. point,Quaternion.identity);
Destroy(GameObject.Find("Click(Clone)"),10);
}
}
using UnityEngine;
using System.Collections;
public class ImageSequenceTextureArray : MonoBehaviour
{
//An array of Objects that stores the results of the Resources.LoadAll() method
private Object[] objects;
//Each returned object is converted to a Texture and stored in this array
private Texture[] textures;
//With this Material object, a reference to the game object Material can be stored
private Material goMaterial;
//An integer to advance frames
public int frameCounter = 0;
void Awake()
{
//Get a reference to the Material of the game object this script is attached to
this.goMaterial = this.renderer.material;
}
void Start ()
{
//Load all textures found on the Sequence folder, that is placed inside the resources folder
this.objects = Resources.LoadAll("Sequence", typeof(Texture));
//Initialize the array of textures with the same size as the objects array
this.textures = new Texture[objects.Length];
//Cast each Object to Texture and store the result inside the Textures array
for(int i=0; i < objects.Length;i++)
{
this.textures[i] = (Texture)this.objects[i];
}
}
void Update ()
{
//Call the 'PlayLoop' method as a coroutine with a 0.04 delay
StartCoroutine("Play",0.00f);
//Set the material's texture to the current value of the frameCounter variable
goMaterial.mainTexture = textures[frameCounter];
}
//The following methods return a IEnumerator so they can be yielded:
//A method to play the animation in a loop
IEnumerator PlayLoop(float delay)
{
//Wait for the time defined at the delay parameter
yield return new WaitForSeconds(delay);
//Advance one frame
frameCounter = (++frameCounter)%textures.Length;
//Stop this coroutine
StopCoroutine("PlayLoop");
}
//A method to play the animation just once
IEnumerator Play(float delay)
{
//Wait for the time defined at the delay parameter
yield return new WaitForSeconds(delay);
//If the frame counter isn't at the last frame
if(frameCounter < textures.Length-1)
{
//Advance one frame
++frameCounter;
/*
if(frameCounter >= 400)
{
objects =null;
textures = null;
goMaterial = null;
frameCounter = frameCounter - 400;
} */
}
Destroy(GameObject.Find("Touch"),10);
//Stop this coroutine
StopCoroutine("Play");
}
}
↧
Destroy 1 prefab object and changing the color/image
I want to destroy a created prefab (not all the prefab) and change the color or creating a new prefab on it. I figure out how to create a new image by using Instantiate on the destroyed position and/or changing the color by using renderer material color. But I want to know how to destroy 1 prefab/clone object that use Instantiate first before doing the rest. Anyone can give me hint or idea on how to do it? Tried using Destroy(this.gameObject), Destroy(gameObject), Destroy(GameObject.FindWithTag), etc but they destroy all of my life.
![alt text][1]
[1]: /storage/temp/36917-untitled.png
using UnityEngine;
using System.Collections;
public class Life : MonoBehaviour {
private GameObject gc;
private GameControl gcs;
public GameObject lifePrefab;
// Use this for initialization
void Start () {
gc = GameObject.Find ("GameControl");
gcs = gc.GetComponent();
}
// Update is called once per frame
void Update () {
// Get the current life from GameControl
if(gcs.getLife() == 2){
// Some code here to destroy 1 prefab life
// Create new different prefab at the same position
Vector3 newLifePos = new Vector3(-1.4f,0.6f,0);
Instantiate(lifePrefab, newLifePos, Quaternion.identity);
}
}
}
↧
↧
FindGameObjectsWithTag returns extra prefabs nowhere in the hierarchy
This is brand new to me. Double-clicking a clone does bring it in focus in the inspector, in which it only has one component out of a bunch and everything is greyed out. Sometimes it doesn't happen, but once it does, it keeps on consistently happening until I restart the editor, in which case it stops happening for a little while. It generally causes one extra instance to appear, but one case had it spawn exactly fifty times.
If that's of any relevance, one of my scripts declares an array of GameObjects like so.
GameObject[] others = new GameObject[all.Length-1];
![Circled in red is the array.][1]
[1]: /storage/temp/29808-phantomclone.png
↧
Assign components to Clone objects
I have a Camera object that needs to follow my player (to create a Mini Map).
I'm using code from the Photon Viki Demo to spawn players,
and it what it does is it creates clones in the Hierarchy ex: Charpref(Clone)10001, Charpref(Clone)40222 and etc... for each player.
How can I get the Mini Map to have each clone as a Target?
**Code from the Photon Viking Demo (in the Asset Store).**
void StartGame()
{
Camera.main.farClipPlane = 100; //Main menu set this to 0.4 for a nicer BG
//prepare instantiation data for the viking: Randomly diable the axe and/or shield
bool[] enabledRenderers = new bool[2];
enabledRenderers[0] = Random.Range(0,2)==0;//Axe
enabledRenderers[1] = Random.Range(0, 2) == 0; ;//Shield
object[] objs = new object[1]; // Put our bool data in an object array, to send
objs[0] = enabledRenderers;
// Spawn our local player
PhotonNetwork.Instantiate(this.playerPrefabName, transform.position, Quaternion.identity, 0, objs);
}
**And here is the "Mini map"** :
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public Transform Target;
void LateUpdate () {
transform.position = new Vector3 (Target.position.x, transform.position.y, Target.position.z);
}
}
**Edit:** I was thinking of possible tagging the Charpref with "Player" and making the Mini Map respond to anything with that tag attached, yet that still didn't work though.
↧
how do you to resolve this unity message
Can´t add component "rigidbody", game object is generatede prefab and only be modified through an assetpostproccesor.
↧