Tag Info

New answers tagged

0

You can use the Update method to update the current volume. private void Update() { VolumeControl(slider.value); } And use the OnApplicationQuit method to save your current volume to the PlayerPrefs. Receiving the saved volume from the PlayerPrefs in the Awake method can be done like in your code snippet, but without the PlayerPrefs.Save statement.


0

using UnityEngine; using UnityEngine.UI; public class SliderSaver : MonoBehaviour { public Slider slider; void Awake () { slider.Value = PlayerPrefs.GetFloat ("Slider value"); } public void OnSliderChange (float newValue) { PlayerPrefs.SetFloat ("Slider value", newValue); } } This sets the slider's value in ...


0

GetComponent<AudioSource>().volume=hSliderValue; This line is C#, not Javascript, or UnityScript.


0

Properties like transform or gameObject are shortcuts for GetComponent<Transform>(). So yes, the GameObject your script is attached to is the Object the script "sees". To your second question im not sure what you mean with manipulate but most of the time the answer is yes. MonoBehaviours should (mostly) only affect the GameObjects they're attached to. ...


0

I have come up with a solution and it seemed to be buried deep within my college memory. I achieved what I wanted through a Unit Circle! Basic calculus/geometry seemed to be the correct way for me to come up with a working solution. I took the x and y translation points of the sun and put them through the unit circle equation. See ...


2

It looks like these two lines are overriding the velocity-based movement from the RigidBody: LillyRB.MovePosition (LillyRB.position + (transform.forward * movever)); LillyRB.MovePosition (LillyRB.position + (transform.right * movehor)); Generally when combining player/AI control with Rigidbody physics, you'll want to use forces & accelerations to move ...


0

I use multiple scripts. A power-up is a prefab which is then composed of multiple components which will then apply the changes separately: Resize Changes Speed Changes (can have configurable values) Health Changes (can have configurable values) Visual Effects (reacts to the start and end of the other scripts) This way each script can be configured to ...


1

From the Unity documentation: Moved A finger moved on the screen. Stationary A finger is touching the screen but hasn't moved. You are checking to see that the fingers are both station and have moved. It is either one of the other. Your code inside the if statements will never run. I see what you are trying to do, but it does not wait after one if ...


2

The Unity3D tutorials actually have a chapter about this: https://unity3d.com/learn/tutorials/modules/intermediate/scripting/coding-practices The author would argue that your switch already gives you a structure to modularize from. You have different effects like Increase Health, Take Damage or Give Item. Those can be astracted in interfaces like ...


1

Single switch script Everything is in one place, better readability. It will be a lot easier to add cases (powerups) when needed. Centralized ressources = good. Multiple scripts Can help when the cases have too much lines. Object-oriented, can be easier to call cases. Looking at your example, the best way to go would be to have one script with a ...


0

Why not use Slider component of uGUI? Its very easy,flexible and resolution independent.Check in, https://unity3d.com/learn/tutorials/projects/survival-shooter/player-health


0

1.) You need to update _lookRotation when the mouse is clicked or it never changes so your agent will never look at a new location. Simple Coroutine Example: IEnumerator RotateAgent(Quaternion currentRotation, Quaternion targetRotation) { IsRotating = true; while(current rotation != targetRotation) { transform.rotation = ...


0

Use Mathf.Lerp() to interpolate between the value you want at 0% and the value you want at 100%. Mathf.Lerp healthBarCurrentX = Mathf.Lerp(healthBarMinX, healthBarMaxX, currentHealth / maxHealth);


0

you could have a black bar, with a green bar painted on top of it. just change length of the bar on top. blackbarlength = 100; percentHealth = (currentHealth / maxHealth) * 100; greenbarlength = percenthealth;


2

There are two options here. Moving the unit at the end of the coroutine (and maybe changing the name of the coroutine) Creating a second coroutine that waits for the first one to finish before executing Now I'll illustrate the examples // 1st option IEnumerator Turn(float _x, float _z) { Vector3 turn = new Vector3 (_x, 0, _z); ...


1

No need for the coroutine, just don't update the position until the rotation has been completed: if(turnComplete){ transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * smooth); } Getting whether the turn is completed means checking how much more the unit needs to turn. If the remaining angle is small enough ...


1

Vector3 targetDirection; float rotationSpeed; void Start() { targetDirection = this.transform.forward; } void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == ...



Top 50 recent answers are included