Questions in topic: "how"http://answers.unity.com/questions/topics/single/2351.html
The latest questions for the topic "how"Terrain turns al black when switching scenehttp://answers.unity.com/questions/1632074/terrain-turns-al-black-when-switching-scene.html
My terrain turns black/deep fried when I switch scenes in my project, I can run it alone just fine but it just can't switch scenes, all of my sprites and props look just fine but the terrain just doesn't
https://imgur.com/a/2ZZsiUO (vid)howWed, 15 May 2019 19:43:54 GMTYouriBuildsGradients color to next gradient color white flash problemhttp://answers.unity.com/questions/1627644/gradients-color-to-next-gradient-color-white-flash.html
when the gradient color to next gradient color, the white flash come out just 1 sec
sometimes I test 3 time, no problem, after the problem come out, mean Sometimes there are problems, sometimes there are no problems
![alt text][1]
Light01 = this.GetComponent<Light>();
//////////////////////////////////////////////////////////////////////////////
if (currentTime >= 18000 && currentTime < 21600)
{
CountHour = 1;
UpdateDawn();
}
if (currentTime >= 21600 && currentTime < 28800)
{
CountHour = 2;
UpdateSunrise();
}
if (currentTime >= 28800 && currentTime < 43200)
{
CountHour = 4;
UpdateMorning();
}
/////////////////////////////////////////////////////////////////////////////
fCurrentTimeOfDay is 0 - 1
void UpdateDawn()
{
Light01.color = DawnColor.Evaluate(test.fCurrentTimeOfDay );
}
//if (isSunrise)
void UpdateSunrise()
{
Light01.color = SunriseColor.Evaluate(test.fCurrentTimeOfDay);
}
//if (isMorning)
void UpdateMorning()
{
Light01.color = MorningColor.Evaluate(test.fCurrentTimeOfDay);
}
unity problem or my programmer problem? 2018.3.14f1
sorry for my bad English
[1]: /storage/temp/137391-screenshot-236.pnghowaskWed, 01 May 2019 19:10:02 GMTjackingyy[Unity 2019] How get distortion effect based on normal map?http://answers.unity.com/questions/1626848/unity-2019-how-get-distortion-effect-based-on-norm.html
I try to get distortion effect on screen such like warm effect from fire, but Partical shader whith turned on distrortion don't work! I remind, what i'm using unity 2019 with lightweight pipeline. First time, i tryed make new one shader in Shader Graph, but pin with name Distortion in master node is missing! WTF?
*(sorry for my english! motherussia)*shaderhowgetdistortionMon, 29 Apr 2019 08:23:19 GMTbonjorno91How to check for colliders when teleporting the player in a 2D game?http://answers.unity.com/questions/1626016/check-for-collision-when-teleporting-the-player-in.html
Hello there!
I'm trying to make my player teleports when hitting the F key but i don't know how to check if there are any collisions on his way. The result is that the player teleports out of the world map and falls down into abysm
How can i make him not going through colliders?
Here's what i did:
if (Input.GetAxis("Horizontal") < 0 && Input.GetKeyDown(KeyCode.F))
{
transform.position = new Vector2(rb.position.x - teleportDistance, rb.position.y);
}
if (Input.GetAxis("Horizontal") > 0 && Input.GetKeyDown(KeyCode.F))
{
transform.position = new Vector2(rb.position.x + teleportDistance, rb.position.y);
}
There's a variable 'teleportDistance' and its set on the Player main script.collision2d game2d-platformerhowteleportingFri, 26 Apr 2019 06:43:46 GMTuleutz123Visual Studio description disappearedhttp://answers.unity.com/questions/1623647/visual-studio-description-disappeared.html
The description of everything just disappeared and, for example, instead of showing thath "Moved" A finger moved on the screen it shows me TouchPhase.Moved = 1. How to fix it? Please help.
/unity 5visual studiohowThu, 18 Apr 2019 19:29:48 GMTElucardLSerialize entire GameObject to xmlhttp://answers.unity.com/questions/1620720/serialize-entire-gameobject-to-xml.html
Hello everyone, I have been trying to serialize a gameObject (including the children) into an xml file and save all the data so I could reconstruct the gameObject on the hololens using just the file!
Is there a simple way to do that?howWed, 10 Apr 2019 08:59:51 GMTElviroI want the space key to act once when pressed even if we hold it what should i do.whats happening is if i long press it starts flying higher ang higherhttp://answers.unity.com/questions/1617014/i-want-the-space-key-to-act-once-when-pressed-even.html
if (Input.GetKey(KeyCode.Space))
{rb.AddForce(0, 55, 0);},howThu, 28 Mar 2019 20:10:47 GMTmarsgaHow to fix Android Gradle Failure in Unity 2018.3.11f1 (64-bit)? Help please!http://answers.unity.com/questions/1615356/how-to-fix-android-gradle-failure-in-unity-201839f.html
How to fix Android Gradle Failure in Unity 2018.3.11f1 (64-bit)? Help please!androidhowfailurefixproblemaSat, 23 Mar 2019 19:36:45 GMTlaynornexosChanging sprites of a 2D object in C#, Can't figure it out!http://answers.unity.com/questions/1615142/changing-sprites-of-a-2d-object-in-c-cant-figure-i.html
I'm trying to make a simple day/night transparent filter, first I get the feeling that I'm using an ineffective and long code, secondly the only change that happens is when sec = 0, I can't figure out why, help is appreciated.
float sec = 45f;
float valueToIncreaseEverySec = 1;
float min = 0;
public Sprite n1;
public Sprite n2;
public Sprite n3;
public Sprite n4;
public Sprite n5;
SpriteRenderer sr;
void Start ()
{
sr = GetComponent<SpriteRenderer> ();
}
void Update()
{
sec += valueToIncreaseEverySec * Time.deltaTime;
print (sec);
if (sec >= 60) {
min++;
sec = 0;
print (min);
}
if (sec == 50f) {
sr.sprite = n1;
}
if (sec == 52.5f) {
sr.sprite = n2;
}
if (sec == 55f) {
sr.sprite = n3;
}
if (sec == 57.5f) {
sr.sprite = n4;
}
if (sec == 0f) {
sr.sprite = n5;
}
if (sec == 2.5f) {
sr.sprite = n4;
}
if (sec == 5f) {
sr.sprite = n3;
}
if (sec == 7.5f) {
sr.sprite = n2;
}
if (sec == 10f) {
sr.sprite = n1;
}
if (sec == 12.5f) {
sr.sprite = null;
}c#spriteobjectifhowFri, 22 Mar 2019 21:20:56 GMTYurivalenNulante Anti-Aging Cream :Achieve Visibly Younger Looking Skin Todayhttp://answers.unity.com/questions/1610348/nulante-anti-aging-cream-achieve-visibly-younger-l.html
The usage of [Nulante Anti-Aging Cream][1] is simple. You need to take after a 3-strengthen method to apply this cream. The three levels will include cleaning, conditioning and after that saturating. previous to the usage of this cream, you are encouraged to wash your face as it should be with water. assure that the soil atoms are expelled from the face. After this, you could delicately observe the cream along with your finger on the stimulated territories. when you have linked the cream, rub the territory delicately with your fingers and allow the cream exhibit its outcomes.you're advocated to make use of this cream once in an afternoon. you can practice Nulante Anti-Aging Cream inside the previous night time dozing and this may give you the exquisite consequences. additionally, it's far informed to drink a extensive degree concerning new water and take sound sustenance at the same time as taking the route of this skin. The strong sustenance, and also drinking water, will guarantee the fine consequences with this item.Click Here https://healthyaustralia.com.au/nulante-anti-aging-cream/
[1]: https://healthyaustralia.com.au/nulante-anti-aging-cream/healthhowFri, 08 Mar 2019 12:51:36 GMTcandaceolivarthe error is : Assertion at ..\mono\mini\unwind.c:620, condition `cfa_reg != -1' not met , how can i fix it?,the error ishttp://answers.unity.com/questions/1608115/the-error-is-assertion-at-monominiunwindc620-condi.html
the error is : Assertion at ..\mono\mini\unwind.c:620, condition `cfa_reg != -1' not met , how can i fix it?,the error ishowSat, 02 Mar 2019 13:44:54 GMTkakiyo9Unity wont let me change to Visual Studio Codehttp://answers.unity.com/questions/1607162/unity-wont-let-me-change-to-visual-studio-code.html
So I have been using Unity for about 3 days now and I have a game I have been making, I want to put a script in my Player I drag it to the Player and it comes up with a message saying, "Can't add script behavior AssembalyInfo. The script needs to derive from MonoBehavior!" Now I read an article saying that I can use Visual Studio Code. Also, I want to add that when I use Mono, it still pops up this message. I have installed the C# extension from Microsoft and the .Net Core (I rebooted my computer as well). This might be an easy fix or a hard one, whatever it is I would LOVE to fix it considering I will not be able to go any farther on my project. (I use personal edition if that helps)spritescript.visual studiohowWed, 27 Feb 2019 22:56:03 GMThappliamdaysi want my sphere character launched to the air when he hits collider. how to do this?http://answers.unity.com/questions/1594700/i-want-my-sphere-character-launched-to-the-air-whe.html
im new to unity and coding.
so l have made a game where you use addforce to a sphere and it starts moving and the goal is to hit cubes. i want to launch the character to the air when the player hits a invisible collider to prevent the player from falling of the platform. How do i do this?addforceforcehowlaunchhow toSat, 26 Jan 2019 19:35:48 GMTryhanenaattoHow to fix a stuck Coroutine / how to have a coroutine running while another scene is openhttp://answers.unity.com/questions/1591749/how-to-fix-a-stuck-coroutine-how-to-have-a-corouti.html
I am making a clicker game and whenever I go to a different scene using SceneManager.LoadScene(2); and come back to the other scene the coroutine gets stuck and isn't fixed until it gets updated. Anyone know a way on how to have the coroutine fix itself or know a way to have the coroutine run itself while another scene is open? I have tested and the coroutine doesn't stop with the console but it does in the in game scripts
(I have just started using the Scene loading function and I am still getting used to it)
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AutoSell : MonoBehaviour
{
public bool SellingOre = true;
public static float CashIncrease = 1;
public float InternalIncrease;
void Update()
{
CashIncrease = GlobalShop.shopPerSec;
InternalIncrease = CashIncrease;
if (SellingOre == false)
{
SellingOre = true;
StartCoroutine(SellTheOre());
}
}
IEnumerator SellTheOre()
{
{
}
if (GlobalOres.OreCount < InternalIncrease)
{
SellingOre = true;
GlobalOres.OreCount = GlobalShop.shopPerSec;
}
else
GlobalCash.CashCount += InternalIncrease;
GlobalOres.OreCount -= GlobalShop.shopPerSec;
yield return new WaitForSeconds(1);
SellingOre = false;
if (GlobalOres.OreCount < GlobalShop.shopPerSec)
{
if (GlobalOres.OreCount >= 1)
{
GlobalCash.CashCount += GlobalOres.OreCount;
GlobalOres.OreCount -= GlobalOres.OreCount;
}
}
}
}
and
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AutoOre : MonoBehaviour {
public bool CreatingOre = false;
public static float OreIncrease = 1;
public float InternalIncrease;
void Update () {
OreIncrease = GlobalMiner.MinePerSec;
InternalIncrease = OreIncrease;
if (CreatingOre == false)
{
CreatingOre = true;
StartCoroutine(CreateTheOre());
}
}
IEnumerator CreateTheOre()
{
GlobalOres.OreCount += InternalIncrease;
yield return new WaitForSeconds(1);
CreatingOre = false;
}
}coroutinehowscene-changestopcoroutinefrozenSat, 19 Jan 2019 03:09:53 GMTunity_0sdsWZad6Fwp-AHow to make the animation collide with wallshttp://answers.unity.com/questions/1590989/how-to-make-the-animation-collide-with-walls.html
Can someone help me how to make the animation collide with walls and/or objects.
![alt text][1]
[1]: /storage/temp/131317-anigif.gifanimationcollisioncollidersfirst-person-controllerhowThu, 17 Jan 2019 02:46:09 GMTPraquenomeI don't want the blues coming out when the camera follows the player.,how do I destroy the blue background in my camera trackinghttp://answers.unity.com/questions/1587899/i-dont-want-the-blues-coming-out-when-the-camera-f.html
Hi ı'm new unity user.
I don't want to see the blue in the back when the camera follows the player.
While my game is playing the camera goes right down. and Cameram follows my player. But I don't want the background blues to appear. I would appreciate it if you could help.
![alt text][1]
[1]: /storage/temp/130750-adsız.png
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class kamer : MonoBehaviour {
public Transform player;
public Vector3 offset;
void Update ()
{
transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z); // Camera follows the player with specified offset position
}
}
,Hi , im new to unity and using unity. the player has the following camera.
I don't want the background blue to appear when playing games and watching the camera player. I would appreciate it if you could help.
![alt text][1]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class kamer : MonoBehaviour {
public Transform player;
public Vector3 offset;
void Update ()
{
transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z); // Camera follows the player with specified offset position
}
}
[1]: /storage/temp/130746-adsız.pnghowhow toTue, 08 Jan 2019 10:04:22 GMTunity_4nxsOi3-5VVdugUnity opens but it won't show anything?,Unity opens , but it doesn't show anyting?http://answers.unity.com/questions/1584738/unity-opens-but-it-wont-show-anythingunity-opens-b.html
Hi guys, i'm new with Unity , i just downloaded it and when i start new project it just takes my desktop background image and doesn't show any commands or assets or anything except the menu ... If anyone knows anything it would help me a lot , thanks in advance :)
[1]: /storage/temp/130175-untitled.png
,Hi guys , i just downloaded and installed Unity , but ,when i open a project it just takes my desktop backgrounds image and doesn't show anything , i will leave a picture here , so if anyone knows anything or could help me solve this , thank you in advance :) ![alt text][1]
[1]: /storage/temp/130174-untitled.pnghowhow toFri, 28 Dec 2018 21:59:30 GMTmperovic2210How to decrease size of linux build?http://answers.unity.com/questions/1579759/how-to-decrease-size-of-linux-build.html
Hello
I am unity developer from Korea
We are developing dedicated server game.
We make build "Host client" to unity "Linux build"
But build size can not decease about 30MB.
How we can decrease Linux build size?
Please help me.linuxhowTue, 11 Dec 2018 08:08:13 GMTlistenportEey how do i get fire1 connected to a UI Buttonhttp://answers.unity.com/questions/1574886/eey-how-do-i-get-fire1-connected-to-a-ui-button.html
if (input.GetButton ("Fire1"))qualityhowfire1Sun, 25 Nov 2018 20:03:03 GMTthechickencreeperHow to send email in c# in Unity 2018.2.17f1http://answers.unity.com/questions/1574530/how-to-send-email-in-c-in-unity-2018217f1.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.UI;
public class userSelectNav : MonoBehaviour {
public void sendMail()
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("senderEmail@gmail.com");
mail.To.Add("recieverEmail@gmail.com");
mail.Subject = "Test Subject";
mail.Body = "Test Body.";
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("senderEmail@gmail.com", "password") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
smtpServer.Send(mail);
Debug.Log("success");
}
catch (Exception ex)
{
Debug.Log(ex);
}
}
}
I got how to do this over at this link:
https://answers.unity.com/questions/433283/how-to-send-email-with-c.html
Don't worry I got the one where people said this works, but it doesn't for me.
I can't show the error cus it's rlly long and I noticed it has my password in some areas.c#systemhowemailFri, 23 Nov 2018 23:39:13 GMTStanlyhaloScript conflicthttp://answers.unity.com/questions/1571741/script-conflict.html
using UnityEngine;
public class VolumeValueChange : MonoBehaviour {
// Reference to Audio Source component
private AudioSource audioSrc;
// Music volume variable that will be modified
// by dragging slider knob
private float musicVolume = 1f;
// Use this for initialization
void Start () {
// Assign Audio Source component to control it
audioSrc = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
// Setting volume option of Audio Source to be equal to musicVolume
audioSrc.volume = musicVolume;
}
// Method that is called by slider game object
// This method takes vol value passed by slider
// and sets it as musicValue
public void SetVolume(float vol)
{
musicVolume = vol;
}
}
The above is my copy script from other sites but I clash with other scripts when I press execute。
My unity already has a Fungus script. What should I do?howWed, 14 Nov 2018 17:00:40 GMTjinen0902Why is an object in a different place from where it should be when i play it?http://answers.unity.com/questions/1567489/why-is-an-object-in-a-difference-place-from-where.html
im very new to unity and programming. when im in the unity program, everything is where it should be, even when i press play. when i build it and run the program, 3 of my objects are in a different place from where they should be. help?newbiehowWed, 31 Oct 2018 15:14:03 GMTdeezeewhyteaHow to make the player can use flutter Jump like Yoshi in Super Mario World?http://answers.unity.com/questions/1566978/how-to-make-the-player-can-use-flutter-jump-like-y.html
I'm new in game development and I tried to do something like Yoshi's flutter jump, but I can't do something functional.
I mean, I want something like this: https://www.mariowiki.com/images/f/f5/Yoshi_Flutter_Jump_Artwork.png
public class Player : MonoBehaviour {
private Rigidbody2D rb2d;
public Vector3 velocity;
public Collision collision;
public float WalkSpeed = 0.5f;
public Vector3 jump;
public float JumpSpeed = 8;
public float JumpForce = 100;
public float JumpDuration;
public bool isGrounded;
public bool isFalling;
void Start () {
rb2d = GetComponent<Rigidbody2D>();
rb2d.velocity = new Vector3(0, 10, 0);
jump = new Vector3 (0.0f, 1.5f, 0.0f);
JumpDuration = 0.5f;
}
void Update () {
WalkMove ();
Jump ();
CheckFall ();
CheckGround ();
}
void WalkMove()
{
//WalkLeft
if (Input.GetKey (KeyCode.LeftArrow)) {
rb2d.transform.Translate (-Vector2.left * 2f * -WalkSpeed * Time.deltaTime);
}
//WalkRight
if (Input.GetKey (KeyCode.RightArrow)) {
rb2d.transform.Translate (Vector2.right * 2f * WalkSpeed * Time.deltaTime);
}
}
void Jump()
{
if (Input.GetKey (KeyCode.UpArrow) || Input.GetKey (KeyCode.Space) && isGrounded == true) {
rb2d.transform.Translate (JumpForce * jump * Time.deltaTime);
if (transform.position.y == JumpDuration) {
rb2d.velocity = Vector3.zero;
}
}
}
void OnCollisionOn(Collision collision)
{
if (collision.gameObject.name == "Platform")
{
isGrounded = true;
}
}
void OnCollisionOut(Collision collision)
{
if (collision.gameObject.name != "Platform")
{
isGrounded = false;
}
}
void CheckFall()
{
if (rb2d.velocity.y < -0.1)//&& Jump
{
isFalling = true;
}
else
{
isFalling = false;
}
}
void CheckGround()
{
if (rb2d.velocity.y == 0)
{
isGrounded = true;
canBoost = false;
}
else
{
isGrounded = false;
canBoost = true;
}
}
}playerjumpprogramminghowTue, 30 Oct 2018 01:13:55 GMTHounriom32bit version of the Unity for Windows 10http://answers.unity.com/questions/1566146/32bit-version-of-the-unity-for-windows-10.html
Do you have the official version of Unity for Windows 10 **32bit**?
Thank.
![alt text][1]
P.S. I don't understand English. I use Google Translate.
[1]: /storage/temp/126710-helpme.jpgunity 5howanswers.unity3d.comFri, 26 Oct 2018 16:34:42 GMTSamexy_69I'm using playerprefs to save scenename and then loading the scenename, it works in the unity engine but not when I build it.http://answers.unity.com/questions/1566129/im-using-playerprefs-to-save-scenename-and-then-lo.html
I have this really simple game, it's the first project I'm working on. I have it so it's saving a scene name through a playerpref in an indestructible object.
void Start () {
DontDestroyOnLoad(this.gameObject);
PlayerPrefs.SetString("lastLoadedScene", SceneManager.GetActiveScene().name);
}
and then loading it through a failscreen retry button.
public void Retry ()
{
string sceneName = PlayerPrefs.GetString("lastLoadedScene");
SceneManager.LoadScene(sceneName);//back to previous scene1?
}gameplayerprefshowFri, 26 Oct 2018 15:18:49 GMTipenguinswarm2D How to get enemy to face the player while movinghttp://answers.unity.com/questions/1555793/2d-how-to-get-enemy-to-face-the-player-while-movin.html
So this is for a top-down action RPG kind of like Zelda, and I've got 4 separate animations for the enemy to face depending on which direction they're moving. I'm trying to get the enemy to follow the player if they're within range, which works, but there's a bit of a delay for the enemy to face the player, and sometimes it'll face a different direction while chasing the player, which looks pretty strange. Any ideas on how to fix this?
testController.cs
public class testController : MonoBehaviour {
public Transform Player;
public float ChaseSpeed = 2f;
public float Range = 4f;
private float CurrentSpeed;
private float attackTimer;
private float attackCooldown = 0.5f;
private bool canAttack;
private Animator anim;
void Start() {
anim = GetComponent<Animator>();
}
void Update() {
if (Vector3.Distance(transform.position, Player.position) <= Range)
{
if (Vector3.Distance(transform.position, Player.position) <= 1f)
{
anim.SetBool("isWalking", false);
CurrentSpeed = 0f;
Attack ();
}
else
{
anim.SetBool("isWalking", true);
anim.SetFloat("input_x", Player.localPosition.x);
anim.SetFloat("input_y", Player.localPosition.y);
CurrentSpeed = ChaseSpeed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, Player.position, CurrentSpeed);
}
}
else
{
anim.SetBool("isWalking", false);
CurrentSpeed = 0f;
}
}playerenemydirectionfollowhowSat, 22 Sep 2018 18:42:54 GMTCutCleavageHow can i pay with paypal without adding a credit card??http://answers.unity.com/questions/1555371/how-can-i-pay-with-paypal-without-adding-a-credit.html
I try to buy something from the asset store. However when i use paypal it keeps asking for a credit card. Can i fix this? because it doesn't always ask for a credit card.,I try to buy some assets from the asset store. However when i select paypal, it keeps asking for a credit card. this doesn't always happen so what should i do to fix it?asset storehowpaypalFri, 21 Sep 2018 08:39:15 GMTR-SchutzGamesHow do I reset game to level one?http://answers.unity.com/questions/1553945/how-do-i-reset-game-to-level-one.html
I am disabled & will play game(s), delete & redownload. Majority of games automatically reset when deleted & downloaded again. Could you pls reset & or provide instructions to reset.
Thank youhowMon, 17 Sep 2018 05:33:13 GMTunity_8GUpOoaQ2dXw0Aunityplayer.dll not working what should I do?,Unityplayer.DLL not working and cant open applicationhttp://answers.unity.com/questions/1546363/unityplayerdll-not-working-what-should-i-dounitypl.html
So recently I downloaded this application on my computer call Vroid it an anime making a 3D app
{here the official site https://vroid.pixiv.net/} I extracted the file like I'm supposed to and as I was trying to open the application it said error unityplayer.dll not found and I redownloaded it and it would not work so I'm at lost and I came here to see if I can solve it please help me!!,I downloaded Vroid a new anime 3D making app but as I extracted the file it wouldn't let me open application it just says error I tried downloading it again and it says the same thing what do did dohowhow-toSun, 26 Aug 2018 05:06:03 GMTcaturaloveMovement with joystick ,Moving object with the Joystckhttp://answers.unity.com/questions/1545198/movement-with-joystick-moving-object-with-the-joys.html
Hi guys i have been working in a mobile game i have two different scripts one for movement and the ther one for the joystick the problem is that i need a way to connect them to make the player move around with the joystick please help me its been a week and i don't know what to do thanks
movement script :
public float m_Speed = 12f; // How fast the tank moves forward and back.
public float m_TurnSpeed = 180f; // How fast the tank turns in degrees per second.
public VirtualJoystick joystick;
private string m_MovementAxisName; // The name of the input axis for moving forward and back.
private string m_TurnAxisName; // The name of the input axis for turning.
private Rigidbody m_Rigidbody; // Reference used to move the tank.
private float m_MovementInputValue; // The current value of the movement input.
private float m_TurnInputValue; // The current value of the turn input.
private void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
}
private void OnEnable()
{
// When the tank is turned on, make sure it's not kinematic.
m_Rigidbody.isKinematic = true;
// Also reset the input values.
m_MovementInputValue = 0f;
m_TurnInputValue = 0f;
}
private void OnDisable()
{
// When the tank is turned off, set it to kinematic so it stops moving.
m_Rigidbody.isKinematic = true;
}
private void Start()
{
// The axes names are based on player number.
m_MovementAxisName = "Vertical";
m_TurnAxisName = "Horizontal";
}
private void Update()
{
// Store the value of both input axes.
m_MovementInputValue = Input.GetAxis(m_MovementAxisName);
m_TurnInputValue = Input.GetAxis(m_TurnAxisName);
}
private void FixedUpdate()
{
// Adjust the rigidbodies position and orientation in FixedUpdate.
Move();
Turn();
}
private void Move()
{
// Create a vector in the direction the tank is facing with a magnitude based on the input, speed and the time between frames.
Vector3 movement = transform.forward * m_MovementInputValue * m_Speed * Time.deltaTime;
// Apply this movement to the rigidbody's position.
m_Rigidbody.MovePosition(m_Rigidbody.position + movement);
}
private void Turn()
{
// Determine the number of degrees to be turned based on the input, speed and time between frames.
float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;
// Make this into a rotation in the y axis.
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
// Apply this rotation to the rigidbody's rotation.
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
}
}
joystick script :
private Image bgImg;
private Image joystickImg;
private Vector3 inputVector;
private void Start()
{
bgImg = GetComponent<Image>();
joystickImg = transform.GetChild(0).GetComponent<Image>();
}
//EventSystems interfaces
public virtual void OnDrag(PointerEventData ped)
{
Vector2 pos;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(bgImg.rectTransform,ped.position,ped.pressEventCamera,out pos))
{
pos.x = (pos.x / bgImg.rectTransform.sizeDelta.x);
pos.y = (pos.y / bgImg.rectTransform.sizeDelta.y);
inputVector = new Vector3(pos.x * 2 + 1, 0, pos.y * 2 - 1);
inputVector = (inputVector.magnitude > 1.0f) ? inputVector.normalized : inputVector;
joystickImg.rectTransform.anchoredPosition = new Vector3 (inputVector.x*(bgImg.rectTransform.sizeDelta.x / 3),inputVector.z*(bgImg.rectTransform.sizeDelta.y/3));
}
}
public virtual void OnPointerDown(PointerEventData ped)
{
OnDrag(ped);
}
public virtual void OnPointerUp(PointerEventData ped)
{
inputVector = Vector3.zero;
joystickImg.rectTransform.anchoredPosition = Vector3.zero;
}
public float Horizontal()
{
if (inputVector.x != 0)
return inputVector.x;
else
return Input.GetAxis("Horizontal");
}
public float Vertical()
{
if (inputVector.x != 0)
return inputVector.z;
else
return Input.GetAxis("Vertical");
}
}androidmovementplayerjoystickhowWed, 22 Aug 2018 23:48:28 GMTBassainaa