Latest Questions on Unity Answershttp://answers.unity3d.com/questions/index.html
The latest questionsGet all Child Transforms in Targethttp://answers.unity3d.com/questions/1282940/get-all-child-transforms-in-target.html
Hello,
I, for some reason cannot get this to work...
All I'm trying to do is to get all the Child Transforms that are present within a target and return them as an array. I have done and followed examples online, including the API, and I get errors.
This is how I have it right now. This gets the return method of the Transforms[]
//get all children on target object
Transform[] _children = (Transform[])_target.GetChildrenOfObject();
Return method:
public Transform[] GetChildrenOfObject(){
Transform[] _transforms;
_transforms = (Transform[])GetComponentsInChildren( typeof(Transform), true );
return _transforms;
}
When I run this, I get the error : Cannot cast from source type to destination type. So I tried:
public Transform[] GetChildrenOfObject(){
Component[] _transforms;
_transforms = GetComponentsInChildren( typeof(Transform), _includeInactive );
return _transforms as Transform[];
}
Which returns a Null...
What am I doing wrong here? (Might be worth mentioning that this code is for an Editor script - so it gets called in Editor Mode, and Play Mode).nullreferenceexceptionreturncastgetcomponentsinchildrenFri, 09 Dec 2016 12:17:33 GMToliver-jonesMathF.clamp not working!http://answers.unity3d.com/questions/1282939/mathfclamp-not-working-1.html
Hi,
I am scaling my game object on mouse dragging, and I want to restrict the scale values, but the objects doesnt stops scaling to min and max while I am dragging to scale it.
Code block :
void OnMouseDrag()
{
gameObject.transform.localScale = new Vector3(Mathf.Clamp(gameObject.transform.localScale.x, 2.8f, 7.2f), gameObject.transform.localScale.y, 1);
}clamplocalscalemathf.clampdraggingscaledownFri, 09 Dec 2016 12:15:40 GMTnj4242How to put clicked object to inventory using raycast (stackable items)http://answers.unity3d.com/questions/1282924/how-to-put-clicked-object-to-inventory-using-rayca.html
I didn't get any compiler errors and i can grab the objects but once an object is in my inventory, other objects with the same tag cannot be picked. This is my script attached to my FPC:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class RaycastShootComplete : MonoBehaviour {
public GameObject inventory; //UI Panel
public GameObject[] items;
public float pickRange = 10f;
public Transform hand;
GameObject pick;
private Camera fpsCam;
private Text amt;
void Start ()
{
fpsCam = GetComponentInParent<Camera>();
}
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
Vector3 rayOrigin = fpsCam.ViewportToWorldPoint (new Vector3(0.5f, 0.5f, 0.0f));
RaycastHit hit;
// Check if our raycast has hit anything
if (Physics.Raycast (rayOrigin, fpsCam.transform.forward, out hit, pickRange))
{
if (hit.rigidbody != null)
{
foreach (Transform child in inventory.transform)
{
if (child.gameObject.tag == hit.transform.gameObject.tag) {
//Assign the text on UI Text to a variable
string txtCount = child.Find ("Text").GetComponent<Text> ().text;
int count = System.Int32.Parse (txtCount) + 1;
child.Find ("Text").GetComponent<Text> ().text = "" + count;
}
}
GameObject item;
if (hit.transform.gameObject.tag == "Apple") {
pick = hit.transform.gameObject;
item = Instantiate (items [0]);
item.transform.SetParent (inventory.transform);
pick.SetActive (false);
Debug.Log ("0");
} else if (hit.transform.gameObject.tag == "Medkit") {
pick = hit.transform.gameObject;
item = Instantiate (items [1]);
item.transform.SetParent (inventory.transform);
pick.SetActive (false);
Debug.Log ("1");
} else if (hit.transform.gameObject.tag == "Oil") {
pick = hit.transform.gameObject;
item = Instantiate (items [2]);
item.transform.SetParent (inventory.transform);
pick.SetActive (false);
Debug.Log ("2");
}
}
}
}
}
}raycastinventoryFri, 09 Dec 2016 11:42:07 GMTAruzcaldoSplash Screen doesn't show up in iOS (Unity 5.5)http://answers.unity3d.com/questions/1282898/splash-screen-doesnt-show-up-in-ios-unity-55.html
I'm trying to release a new version of my game building it with Unity 5.5.
Currently I'm using a personal edition license so I expect to see the default Unity Logo when I launch the App from a device but I only get a black screen... then my game starts normally.
I've tried to change settings from the Splash Screen area setting it to static and all the other possible combinations... nothing to do.
Any suggestion? is this a known bug? I cannot find any other similar issue related to Unity 5.5. here.unity 5splash screenFri, 09 Dec 2016 10:51:24 GMTBitwakerBools not changing...http://answers.unity3d.com/questions/1282905/bools-not-changing.html
I have voids that make a player move to a different spot on my map and should enable or disable some bools. I'm calling them from button onclicks. The player moves to the spot, but the bools don't change. The bools seem to change only when i put them in the start function. Just to be a bit more clear as well, they aren't setting as true, then turning back to false. They never turn true in the first place. This is also a networkbehavior script.
public Rigidbody Player;
public Camera PlayerCamera;
public AudioListener PlayerAudio;
public Camera SpectateCamera;
public AudioListener SpectateAudio;
public MeshRenderer Body;
public MeshRenderer Head;
public Collider BodyCollider;
public Collider HeadCollider;
GameObject PlayerBody;
bool ControllerEnabled;
bool PlayerCameraEnabled;
bool PlayerIsVisible;
bool GravityEnabled;
public void EnterSpectateMode()
{
PlayerCameraEnabled = false;
PlayerIsVisible = false;
GravityEnabled = false;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(500, 30, 675);
}
public void JoinRedTeam()
{
PlayerCameraEnabled = true;
PlayerIsVisible = true;
GravityEnabled = true;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(617, 10, 500);
PlayerBody.transform.localRotation = Quaternion.Euler(0, -90, 0);
}
public void JoinBlueTeam()
{
PlayerCameraEnabled = true;
PlayerIsVisible = true;
GravityEnabled = true;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(383, 10, 500);
PlayerBody.transform.localRotation = Quaternion.Euler(0, 90, 0);
}
void Start ()
{
EnterSpectateMode();
}
void Update ()
{
if (PlayerCameraEnabled)
{
PlayerCamera.enabled = true;
PlayerAudio.enabled = true;
SpectateCamera.enabled = false;
SpectateAudio.enabled = false;
}
else
{
SpectateCamera.enabled = true;
SpectateAudio.enabled = true;
PlayerCamera.enabled = false;
PlayerAudio.enabled = false;
}
if (PlayerIsVisible)
{
Body.enabled = true;
BodyCollider.enabled = true;
Head.enabled = true;
HeadCollider.enabled = true;
}
else
{
Body.enabled = false;
BodyCollider.enabled = false;
Head.enabled = false;
HeadCollider.enabled = false;
}
if (GravityEnabled)
{
Player.useGravity = true;
}
else
{
Player.useGravity = false;
}
This seems very odd. Can anyone see why this isn't working? Thanks in advance.boolvoidFri, 09 Dec 2016 10:50:53 GMTBrylosHow to save and Load components. Help!http://answers.unity3d.com/questions/1282890/how-to-save-and-load-components-help.html
I need help to be able to save and load components like public gameobject and nav mesh paths. OR if possible to save and load the Scene.
Thanks, Ben.saveloadsave gameFri, 09 Dec 2016 09:49:14 GMTBjb5656Operator `+' cannot be applied to operands of type `UnityEngine.Vector3' and `float'http://answers.unity3d.com/questions/1282889/operator-cannot-be-applied-to-operands-of-type-uni-3.html
Simple but out of my head, (Much noob)
What's with this error, I know what it means, but I don't know where I am wrong:
spriteBound = gameObject.GetComponent<SpriteRenderer>().sprite.bounds;
vector3 upperLeft = transform.position - transform.right * spriteBound.extents.x + transform.up + spriteBound.extents.y;
Thankserrorgameobjectvector3transform.positionboundsFri, 09 Dec 2016 09:46:15 GMTnj4242Increase thickness of outlineshttp://answers.unity3d.com/questions/1282886/increase-thickness-of-outlines.html
Hi,
I want to add another property to increase the size/thickness of the outline in the following shader:
Shader "Custom/Sprite Outline" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Cull Off
Blend One OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f {
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;
return o;
}
fixed4 _Color;
float4 _MainTex_TexelSize;
fixed4 frag(v2f i) : COLOR
{
half4 c = tex2D(_MainTex, i.uv);
c.rgb *= c.a;
half4 outlineC = _Color;
outlineC.a *= ceil(c.a);
outlineC.rgb *= outlineC.a;
fixed alpha_up = tex2D(_MainTex, i.uv + fixed2(0, _MainTex_TexelSize.y)).a;
fixed alpha_down = tex2D(_MainTex, i.uv - fixed2(0, _MainTex_TexelSize.y)).a;
fixed alpha_right = tex2D(_MainTex, i.uv + fixed2(_MainTex_TexelSize.x, 0)).a;
fixed alpha_left = tex2D(_MainTex, i.uv - fixed2(_MainTex_TexelSize.x, 0)).a;
return lerp(outlineC, c, ceil(alpha_up * alpha_down * alpha_right * alpha_left));
}
ENDCG
}
}
FallBack "Diffuse"
}
I am using this shader to outline a 2d sprite which has is semi-transparent.
Any help would be appreciated.
Thanks2dshaderspriteoutlineFri, 09 Dec 2016 09:29:24 GMTnj4242Transparant PNG Not workinghttp://answers.unity3d.com/questions/1282880/transparant-png-not-working.html
I made some sprites with paint.net, which are supposed to have a transparant background, but when i import them into unity, they all suddenly get black backgrounds. I have no idea why this happens. also, im sure they are PNG files.![alt text][1]
![alt text][2]
[1]: /storage/temp/83707-schermafdruk-2016-12-08-084908.png
[2]: /storage/temp/83708-schermafdruk-2016-12-08-124746.pngimagetransparencypaint.netFri, 09 Dec 2016 09:11:34 GMTruneskape125.Net Framework install error/http://answers.unity3d.com/questions/1282869/net-framework-install-error.html
I updated to 5.5 in windows 10. During install I get a error saying Unity may stop working correctly. The problem is with this and yes Unity did malfunction, especially with the terrain, is we are are using .Net framework 4.5 and 4.6.
It seems then odd to me with a new version of U5 that its not using the current framework. Why is this?softwareFri, 09 Dec 2016 08:30:32 GMTArch_WarlockAfter i made my quad as a prefab everything stop showing cannot add or see and assetshttp://answers.unity3d.com/questions/1282868/after-i-made-my-quad-as-a-prefab-everything-stop-s.html
I Am creating an endless runner 2D game for my project. I adding a quad which would take the scene to the game over if the player fall and touches it. After doing that i decided to make the quad as a prefab but the movement i took the prefab to the scene everything went grey and can only see the game in the game scene but not on the #scene. if you could advise how can i make it visible back?
!![alt text][1]
[1]: /storage/temp/83706-screen-shot-2016-12-09-at-42333-pm.pngrigidbody2dFri, 09 Dec 2016 08:30:28 GMTiamjagpreetdWhen i click reset button this function is called.Here i want to load the Last texture saved by user by name -usertexture.png.Now whenever i load this image into unity and apply it to model it just turns black. I am new to unity :Dhttp://answers.unity3d.com/questions/1282830/when-i-click-reset-button-this-function-is-calledh.html
using UnityEngine;
using System.Collections;
public class FirstLoad : TexturePainter
{
public GameObject gameobj;
void Update () {
}
public IEnumerator LoadUserTexture()
{
string fileName = "UserTexture.png";
string fullPath = Application.persistentDataPath + "\\UserdEdited\\"+ "UserTexture.png";
WWW www = new WWW("file:///" + fullPath);
yield return www;
gameobj.GetComponent<MeshRenderer>().material.mainTexture = www.texture;
}
public void loadtexture()
{
StartCoroutine("LoadUserTexture");
}
}unity 5textureloadingblackFri, 09 Dec 2016 06:20:06 GMTmalodiaHow can I make my character constantly run right? Pleasehttp://answers.unity3d.com/questions/1282819/how-can-i-make-my-character-constantly-run-right-p.html
private void Update()
{
if(Input.GetKeyDown(KeyCode.UpArrow))
{
if(canJump == true)
{
rigidbody2d.AddForce(new Vector2(1, 500));
canJump = false;
}
}
}
/*
* If the player has collided with the ground, set the canJump flag so that
* the player can trigger another jump.
*/
private void OnCollisionEnter2D(Collision2D other)
{
canJump = true;
}
}movementFri, 09 Dec 2016 06:20:03 GMTmiguelnaidooRotation Lerp from -1 to 3 goes around the whole object?http://answers.unity3d.com/questions/1282812/rotation-lerp-from-1-to-3-goes-around-the-whole-ob.html
Hi,
im using EulerAngles and Lerp to make a small rotation from -1 to 3, but instead of going simply 4 steps, it goes all the way around.
The used code is:
obj.transform.localRotation = Quaternion.Euler(Vector3.Lerp(StartRotation, TargetRotation, Lerp));
**StartRotation** is where the animation started. Ex.: `new Vector3(0,-1,0)`
**TargetRotation** is the TargetRotation. Ex.: `new Vector3(0,3,0)`
**Lerp** is the time whent by using this: `Lerp += Time.deltaTime;`
-
Does anyone have an idea why it bahves like this? Im new to the engine, so sorry if its a stupid question.animationlerpFri, 09 Dec 2016 06:19:52 GMTCokemonChange position of object while it undergoes lerphttp://answers.unity3d.com/questions/1282808/change-position-of-object-while-it-undergoes-lerp.html
So I have a sphere that starts at a position, and needs to move to another position in a specific amount of time.
Vector3 startPosition = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 endPosition = new Vector3(0.0f, 10.0f, 0.0f);
float tSeconds = 2.0f;
float tDelta = 0.0f;
void Update()
{
tDelta += Time.deltaTime / tSeconds;
transform.position = Vector3.Lerp(startPosition, endPosition, tDelta);
}
It works fine but what if I need another script to change the sphere's position on the Y axis to let's say 2 when it reaches 7. How do I do that without affecting the Update() function inside the sphere itself? I tried to even manipulate it in the editor but the position doesn't save and resets to where it was before. How do I go about re-creating this function so that I can edit the sphere's position at any time without rigidbody velocities or other components.transformtimelerpFri, 09 Dec 2016 06:19:50 GMTFrateMareProblem with camera and character controller (fighting game)http://answers.unity3d.com/questions/1282806/problem-with-camera-and-character-controller-fight.html
I want to make a 3D fighter.
The cámera is always behind the player, but it points to the enemy player that is also moving in 3D space.
I want my movement to be influenced by the camera (who is influenced by the enemy player). With influenced by the camera I mean that if I press the right arrow, I dont want my character moving relative to the game default axis, instead I want to move right relative to the current camera rotation.
Any suggestions how to make the movement relative to the camera?cameramovementplayerfightingFri, 09 Dec 2016 06:19:46 GMTFuranA7xvisual studio "attach to unity and play" how to stop on error?http://answers.unity3d.com/questions/1282790/visual-studio-attach-to-unity-and-play-how-to-stop.html
i love visual studio's "attach to unity and play" (when it works, sometimes it a bit flaky but mostly good)
the only thing is, if i have compile errors, it starts unity anyhow. this is very confusing if you don't notice, and i'd like it so give me an error message and not start unity, so i can fix the error.
is there a setting for that?
thanksvisual studioFri, 09 Dec 2016 06:19:40 GMTsteveh2112Restart button not functioning properlyhttp://answers.unity3d.com/questions/1282784/restart-button-not-functioning-properly.html
Hello! I am trying to create a button that pops up once my game is over, to allow players to restart the game. The way I have it set now, the button pops up three seconds after the game is over. The problem is that you can click the button all you want, but nothing happens. And the strange part is that in the Unity editor, I have the button hidden because I obviously don't want it appearing while the game is being played but if check the box and make it visible at all times...it works properly and restarts the game! Any ideas on why that is or what I can do to make it work properly once the gameplay is over? Thanks in advance!buttoninspectorunityeditorrestart gameFri, 09 Dec 2016 06:19:38 GMTDKitch9Ello, i'm new to unity but I keep getting this error in my script?http://answers.unity3d.com/questions/1282779/ello-im-new-to-unity-but-i-keep-getting-this-error.html
using UnityEngine;
using System.Collections;
public class character : MonoBehaviour {
//movement variables
public float maxspeed;
Rigidbody2D myRB;
Animator myAnim;
bool facingRight
// Use this for initialization
void Start () {
myRB = GetComponent<Rigidbody2D> ();
myAnim = GetComponent<Animator> ();
facingRight = true;
}
// Update is called once per frame
void FixedUpdate () {
float move = Input.GetAxis ("Horizontal");
myAnim.SetFloat ("speed", Mathf.Abs (move));
myRB.velocity = new Vector2 (move * maxspeed, myRB.velocity.y);
if (move < 0 && facingRight) {
flip ();
} else if (move < 0 && facingRight) {
flip ();
}
}
void flip() {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}errorvoidFri, 09 Dec 2016 06:19:36 GMTkittehmunsterzvery funny problems,a function doesn't excute to the endhttp://answers.unity3d.com/questions/1282778/very-funny-problemsa-function-doesnt-excute-to-the.html
![alt text][1]
![alt text][2]
[1]: /storage/temp/83695-step1.png
[2]: /storage/temp/83696-step2.png
so,the problem is this function didn't get excuted to the end,it just break at the GameObject.Find function call.and the excution flow goes to another script.so what happened?it's very funny that this function somehow breaked before it's done,the rest of the Debug.Log didn't even get excuted.i'll post another image to show the next step the excution goes to another script directly. if i comment out the code in that if scope,the rest of the code gets excuted as normal.strange? isn't it?
this function should be called when SceneManager set my game scene to be active.as you see, this is an event callback.sorry for my english,i'm not a native english speaker.so maybe we can discuss about
this funny problem.what happened behind this
and there's an error below i don't quite understand 'fillTime The identifier `fillTime` is not in the scope' what is this errror?c#eventsmethodgameobject.findFri, 09 Dec 2016 06:19:32 GMTlklqlkSound issues.http://answers.unity3d.com/questions/1282775/sound-issues-2.html
I place a sound source on an object, but even after turning down how far away the sound is to be heard ( as in you can hear it fade as you move away from it), it still plays at the same strength throughout the scene as though its attached to the character (which it isn't).
I am currently in 5.5 recent update and what I was doing before where this was not a problem does not work now. Any assistance would be appreciated.sound effectsFri, 09 Dec 2016 06:19:30 GMTArch_WarlockRoll a Ball Tutorial does not work. Help?http://answers.unity3d.com/questions/1282773/roll-a-ball-tutorial-does-not-work-help.html
I did the Roll a Ball Tutorial (movement) twice (even copied the script they give you) and both times it didn't work. One time it didn't move. The Second time it didn't move except when I hit the down arrow, which makes it fly straight up. Also when I close Unity and then re-open it all my objects are gone. (platform and sphere). I am super confused, also getting really annoyed because this is my second day trying this program and have already found some errors. Can anyone help me? REALLY FRUSTRATED!!!unity 5tutorialglitchroll a ballFri, 09 Dec 2016 06:19:27 GMTLhp174How to not alter Line Renderer's colour with the camera's background(skybox)?http://answers.unity3d.com/questions/1282769/how-to-not-alter-line-renderers-colour-with-the-ca.html
I want the line to be grey, but the background(skybox) alters the color of the line.
![alt text][1]
![alt text][2]
[1]: /storage/temp/83694-unity-problem-white.jpg
[2]: /storage/temp/83693-unity-problem-black.jpgc#Fri, 09 Dec 2016 06:19:20 GMTnafiz3008comparing variables of gameobjects in an arrayhttp://answers.unity3d.com/questions/1282761/comparing-variables-of-gameobjects-in-an-array.html
Hello, I have an array with two game objects in it and I want to compare their int variables "ATK" and see which one is bigger (and then destroy the game object that has the smaller). The problem is that the specific game objects that make up the array change throughout the game so I want to call the ATK variable just using the index of the array and I don't know how to access a game object's variables in an array like that
I don't know if I managed to ask my question clearly but any help would be appreciated!c#arrayvariablesgameobjectsFri, 09 Dec 2016 06:19:10 GMTSimplyMabuUsing a shader for Europa Universalis-style province coloring.http://answers.unity3d.com/questions/1282753/using-a-shader-for-europa-universalis-style-provin.html
Hi. I'm working on a Paradox-style grand strategy with a map divided into provinces. Currently I'm just using nodes, but figured that actual blobbed regions would work better, as I could colour them depending on what country owns them.
Now, I've been investigating shaders to achieve this effect. I also know that Paradox uses an [image][1] of their provinces, each with a different RGB colour. I figured their shader must work something like:
// Array of province code-colors.
float4 codeColors[100]
// Array of the actual colors of each province.
float4 provinceColors[100]
frag()
{
// For each codeColor, if pixel matches codeColors[x], return provinceColors[x].
}
where provinceColors would represent codeColors index-for-index, and could be set externally when a province is captured (Rome has captured Syracuse? Set provinceColor48 to Rome.color).
I'm finding that there are a few issues with this. The first is that shaders don't handle if-statements well, let alone for-loops of them. It's apparently very bad for performance to just have a few if statements. Second, it seems that comparing colours exactly isn't always a sure-fire thing, and is better done with thresholds (Is x colour within 10% of y value?). This is very error-prone for this system.
Knowing this, is there a better way to achieve what I want?
[1]: http://www.paradoxian.org/eu3wiki/eu3wiki_images/thumb/a/ad/Provinceshttt.jpg/580px-Provinceshttt.jpgshadersif-statementsstrategyFri, 09 Dec 2016 06:19:03 GMTThomas-SladeCollision causes object to fly away at high velocityhttp://answers.unity3d.com/questions/1282745/collision-causes-object-to-fly-away-at-high-veloci.html
I have a game where the user can fly a ship into islands to destroy them. When the ship collides with any of my islands, the island will seem to disappear but after further investigation, I observed the island just moves extremely far away instantaneously and then stops. I've changed the mass and drag but they don't seem to be having an effect. Why is collision adding so much force?
This is the ship object
![alt text][1]
This is the Island object, the mass and drag are set to 100 in the code
![alt text][2]
This is a link to the apk to test out.
[link text][3]
[1]: /storage/temp/83688-shipmodel.jpg
[2]: /storage/temp/83691-islandmodel.jpg
[3]: https://drive.google.com/open?id=0BzLV70xmX5jlVUVXX3dWNXd3LTAvelocitydragmasscollision issuesFri, 09 Dec 2016 06:18:49 GMTAllmightysmiterModifying a variable outside of player object.http://answers.unity3d.com/questions/1282735/modifying-a-variable-outside-of-player-object.html
Hi, im trying to create a 2D multiplayer game.
I have this bool isBoosted changed to true when it collides with something like some sort of a speed up.
Here is the script that modifies it.
public class MultiPowerUpRun : MonoBehaviour {
// Use this for initialization
public float boostTime;
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Player") {
other.GetComponent<PlayerManager>().isBoosted = true;
if(GameController.control.speedlvl == 0){
boostTime = 4f;
}
if(GameController.control.speedlvl == 1){
boostTime = 4.5f;
}
if(GameController.control.speedlvl == 2){
boostTime = 4.7f;
}
if(GameController.control.speedlvl == 3){
boostTime = 5f;
}
if(GameController.control.speedlvl == 4){
boostTime = 5.5f;
}
if(GameController.control.speedlvl == 5){
boostTime = 6f;
}
//other.GetComponent<PlayerManager>().resetIsBoosted(boostTime);
Destroy(gameObject);
}
}
}
Now here in my playerscript. I print out the value of isBoosted and my speedX.
Here is the script
public class PlayerManager : NetworkBehaviour{
static float speedX;
static float speedY;
static bool facingright;
static bool isShooting;
static Animator anim;
static Rigidbody2D myBody;
public bool isBoosted;
void Update (){
Debug.Log ("Boosted: " + isBoosted + " SpeedX: " + speedX);
if (isLocalPlayer) {
if(isAlive){
anim.SetBool("isAlive",true);
MovePlayer (speedX);
ariusManager(meterCount);
if (facingright && speedX < 0 || !facingright && speedX > 0) {
facingright = !facingright;
flipHere ();
CmdSendFlip (transform.localScale.x);
}
anim.SetFloat ("verticalSpeed", myBody.velocity.y);
anim.SetBool ("isShooting", isShooting);
if (isShooting) {
Invoke ("resetShooting", 0.4f);
}
}
else{
anim.SetBool("isAlive",false);
}
LocalPop();
}
}
void MovePlayer(float playerSpeed){
myBody.velocity = new Vector3 (playerSpeed, myBody.velocity.y, 0);
}
public void WalkLeft(){
if (!isAlive) {
return;
}
if (isBoosted) {
speedX = -20;
} else {
speedX = -9;
}
anim.SetBool ("Speed", true);
pumpRelease ();
}
public void WalkRight(){
if (!isAlive) {
return;
}
if (isBoosted) {
speedX = -20;
} else {
speedX = -9;
}
anim.SetBool ("Speed", true);
pumpRelease ();
}
when the value of isBoosted is changed to true. I was expecting to see in the console "Boosted: True SpeedX: 20 or -20" but instead i still get "Boosted: True SpeedX: 9 or -9"c#multiplayerFri, 09 Dec 2016 06:18:33 GMTlegitplayer09why I have this weird shading? (I'm newbie in unity)http://answers.unity3d.com/questions/1282729/why-i-have-this-weird-shading-im-newbie-in-unity.html
why I have this weird shading? I don't know if this from material or mesh.
first image is only sphere and shading is look weird.
the second image is using default material (if i remember, i only change the color)
![alt text][1]
![alt text][2]
[1]: /storage/temp/83686-2.png
[2]: /storage/temp/83687-capture.pngshadermateriallightingFri, 09 Dec 2016 06:18:30 GMTNico5Change object's name by input fieldhttp://answers.unity3d.com/questions/1282727/change-objects-name-by-input-field.html
I'm making kind of level editor, I would like to have the possibility to change object's name.
When I'm placing objects, then, when right clicked, I display some GUI.Box with "Change name" button, when the button is clicked, then the canvas is enabled, on the canvas I've got an Input Field and... what now? How can I connect the Input fields value with the name of the clicked object?runtimeinputfieldgameobject.nameFri, 09 Dec 2016 06:18:28 GMTLoGi123How do you detect which collider is triggered when you have multiple?http://answers.unity3d.com/questions/1282725/how-do-you-detect-which-collider-is-triggered-when.html
I have an enemy gameobject with 3 colliders attached to it, one is a trigger to tell it when something is in it's "sight" to target other enemies, there is another trigger to detect when something is hit by it's attacks, and a third that is not a trigger to detect when it gets hit by attacks. The problem is that I cant find a way to tell which of the two trigger colliders is being triggered with the OnTriggerEnter() method. I need it to do separate things when the sensor trigger is hit than when something is in it's attack range. I have all of the colliders in my code as variables so I can differentiate between them but I can't find a variable for the collider that calls the OnTriggerEnter() method. Here is the code for my enemy class:
public int health, damage;
//Linger = time the attack stays active, Delay = for the player to dodge attacks before they activate
public float linger, delay, range, attackRange, speed;
//Accumulation of time between updates to tell how ling it's been since an attack started
private float timePassed;
private Transform target;
private bool attacking = false;
//Two trigger colliders sensor is used to aquire a target, attackCol is used to deliver attacks
public SphereCollider sensor, attackCol;
public void Start()
{
attackCol.enabled = false;
sensor.radius = range;
attackCol.radius = attackRange;
}
public void Update()
{
if (attacking)
{
timePassed += Time.deltaTime;
}
if (timePassed >= delay)
{
attack ();
}
if (timePassed >= linger + delay)
{
attacking = false;
attackCol.enabled = false;
timePassed = 0;
}
if (target != null && !attacking)
{
attackTarget(target, Time.deltaTime);
}
}
public void attackTarget(Transform t, float deltaTime)
{
//Checks if the target is in attack range
float distance = Mathf.Sqrt (Mathf.Pow (t.position.x - transform.position.x, 2) + Mathf.Pow (t.position.y - transform.position.y, 2));
if (distance > attackRange / 2) {
attack ();
attacking = true;
} else {
//Faces and moves toward the target
transform.rotation = Quaternion.Euler(0, getAngle(transform.position, t.position) * (180/ Mathf.PI), 0);
transform.position += new Vector3(Mathf.Cos(getAngle(transform.position, t.position)), 0, Mathf.Sin(getAngle(transform.position, t.position))) * speed * deltaTime;
}
}
public void attack()
{
attackCol.enabled = true;
}
public void OnTriggerEnter(Collider other)
{
if(other.gameObject.GetComponent<Player>() != null)
{
target = other.transform;
}
}
The colliders are set in the inspector and although you cant tell the difference by name I made sure they are not the same collider listed twice
![alt text][1]
And both colliders show up in the editor when the game is run
![alt text][2]
[1]: /storage/temp/83684-capture.png
[2]: /storage/temp/83685-capture2.png
However the script cannot tell the difference between the two trigger colliderscollidertriggerFri, 09 Dec 2016 06:18:27 GMTDrakon0168