• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Indie Game Development Discussion Thread | Of Being Professionally Poor

Status
Not open for further replies.

billsmugs

Member
i'm not sure exactly what you mean. in unity there's multiple ways of controlling your movement. you can do it via the physics engine and add force to a rigidbody (a ragdoll like object) or you can control it directly via a speed you set to modify yourself.

by default in the physics engine, you wouldn't be able to move at all in the air without building up momentum on the ground. if you control it directly via character controller you'd move exactly the same in the air as you would on the ground unless you specified it to act differently at the two separate times. you can create as many whacky styles of movement that you can dream of in unity, it does movement really well.

If you jumped in a direction in real life you wouldn't be able to change direction until you hit the ground but in most platformers you can, he just seems to want to know how much damping goes on with most platformers when changing direction in mid air.

Personally, I have no experience with platformers, but I'd probably build my character movement around movement angle, velocity and acceleration. Then when accounting for in-air movement, maybe use half the acceleration.

I'm using a character controller and I've got the basic movement and jumping sorted. (I tried to get it working with a rigidbody player, but there were all sorts of little problems and issues and I wouldn't have used it for anything special in gameplay. I just like being able to knock over piles of boxes!) At the moment the player has full control in the air (full speed, instant direction changing, ability to halt all horizontal motion instantly), which seems like too much, but I'm not sure how much to limit it (or in what way). The main problem I have with just using e.g. half acceleration in the air is that if the player isn't moving when they jump, it can be tricky to travel anywhere in the air. (Meaning that the player needs a run up to make simple jumps).

I might try lerping the horizontal components of the velocity between the values when the jump starts and the new input made while in the air and see how that goes.

Also, what do people think about having a (very?) short interval in which the player can jump after physically running off the edge of the platform? I know a few 2D platformers do this, but I don't know if it would look right in 3D? It might not be necessary if the player can glide back and climb up if they don't jump in time, but it might be less frustrating?

Finally, something that might be best asked on the Unity forums/answers, but I'll ask it here first: If speeds are multiplied by Time.deltaTime, they should be in relation to real time, not affected by framerate, shouldn't they? I'm multiplying all my speeds by this and using it in Lerps, but if I change the Vsync settings (to limit the framerate and stop my laptop kicking into overdrive whenever I hit play with loads of other things open), I can't jump as high. Is this because I'm recreating the movement vector each frame, rather than adding to it? If I get rid of the Time.deltaTime multiplier then my jump height seems unaffected by frame rate, but the jump speed is affected. Is this something specific to how Vsync works, or am I doing something wrong with my code? (I assume the latter!)

EDIT: Also, should the player's time in the air during a jump be the same for all jumps, or the jump height? I know physically speaking it should be the airtime, but I don't know if that is normally the case for platfom games?

A lot of my questions will come down to just trying different methods and seeing which feels/plays best, but I'd be interested in other people's opinions and experiences with 3D platformers (as I said, specifically Ratchet & Clank, but if other games do things differently I'd be interested in those as well).
 

MrOddbird

Neo Member
28-4-2013.png

A screenshot from the horror game I've been making with Unity.
I love this engine! It allows really fast iterations and it's very fast to use.

I've at tried to do Gamma Calibration for my screen, so hopefully it isn't too dark or too bright.
 

Anustart

Member
A screenshot from the horror game I've been making with Unity.
I love this engine! It allows really fast iterations and it's very fast to use.

I've at tried to do Gamma Calibration for my screen, so hopefully it isn't too dark or too bright.

That shot looks really good! I would love to use Unity as intended and do 3D but I do not have any ability in modeling/animating, so 2d it is!
 

MrOddbird

Neo Member
That shot looks really good! I would love to use Unity as intended and do 3D but I do not have any ability in modeling/animating, so 2d it is!

My plan was that if I was going to make a 3D game, I needed to know a bit about modelling.

I thought it would be super hard, but after watching 20 minutes of tutorials, editing a small cube in Blender, plus applying UV maps and finally importing it to Unity, there was a feeling of accomplishment I hadn't felt for a very long while.

When you add a simple normal map to the texture, the feeling that you created something so amazing in such a short time is so satisfying.

Seriously, 3D modelling in my opinion is a much process than creating 2D sprites.

Animation is still a thing I really cannot do correctly. However just like with the first time creating a model, my first animation was just so great to see in the engine.

There's still a lot to learn, but if you really want to continue making games than learning the basics of 3D modelling is absolutely a great benefit you can have and it doesn't really take that long to make something.
 

eot

Banned
EDIT: Also, should the player's time in the air during a jump be the same for all jumps, or the jump height? I know physically speaking it should be the airtime, but I don't know if that is normally the case for platfom games?

They should both be invariant with respect to framerate.
As for your time delta problem, how is your gravity implemented? You need to make sure that it scales with framerate as well.
 

Nezzhil

Member
Well, I finished my game for the Lundum Dare,solo and 48 hours (developed in Java):

MiniCrawler
Captura-550x543.png

Game (require Java 7)
Code

And… finally… the chronolapse:
http://www.youtube.com/watch?v=V5HMEKcOMEs

I'm not a graphic artist, but I tried the best with the time limit and the old GameBoy palette.
The only controls are the cursors.
The game have 7 levels (6 + the testing level like a bonus) and is a bit hard because the Player's collision box is big, but my brother has finished the game, so it possible! Haha.

This is my third entry in a gamejam like event. This (my first solo) and two local events with a little team.
 

Noogy

Member
A screenshot from the horror game I've been making with Unity.
I love this engine! It allows really fast iterations and it's very fast to use.

I've at tried to do Gamma Calibration for my screen, so hopefully it isn't too dark or too bright.

Every time I see something like this I want to take a little break from working on my own engine and do something in 3D. I'm actually a pretty good modeler/animator, although I haven't done 3D world building since the first Unreal engine. If only there were more time :p
 

ikkei

Member
A screenshot from the horror game I've been making with Unity.
I love this engine! It allows really fast iterations and it's very fast to use.

I've at tried to do Gamma Calibration for my screen, so hopefully it isn't too dark or too bright.
That looks neat. Can I ask you if that cave was built as a single object or with many modular parts?
 
Every time I see something like this I want to take a little break from working on my own engine and do something in 3D. I'm actually a pretty good modeler/animator, although I haven't done 3D world building since the first Unreal engine. If only there were more time :p

Are you available for any contract work (3d character animation, maybe some modeling) in the future? I could use it for my next Dungeon Hearts game so I can focus more on the design and programming. It wouldn't be for a while though, I'm just starting the prototyping phase for the next game.
 

Noogy

Member
Are you available for any contract work (3d character animation, maybe some modeling) in the future? I could use it for my next Dungeon Hearts game so I can focus more on the design and programming. It wouldn't be for a while though, I'm just starting the prototyping phase for the next game.

I might be interested in doing some 3D stuff yeah. It'd be a nice way to brush up my 3D skills (for games). Most of my work has been film oriented, although I did what you might call glorified mod work in Unreal many years back. PM me!
 

billsmugs

Member
They should both be invariant with respect to framerate.
As for your time delta problem, how is your gravity implemented? You need to make sure that it scales with framerate as well.

In that edit, I was thinking about how they should behave without any frame rate issues, but looking at the gravity, I don't think I have been scaling by frame rate properly. However, when I did, it ruined the feel of the jump and made me realise that I need to rework my gravity implementation! If I still have problems after I've done that then I'll post my code here, but I think the problem was that I was only scaling a time factor by Time.deltaTime, not the speed factors as well.
 

eot

Banned
What do you mean with "speed factors"? :p
To make it frame rate independent you should only have to scale with Time.deltaTime. Of course there might be some different behaviour you want.
 

billsmugs

Member
What do you mean with "speed factors"? :p
To make it frame rate independent you should only have to scale with Time.deltaTime. Of course there might be some different behaviour you want.

I was scaling the time over which the speed changed, but not the output speed itself (I realise now that "speed factor" doesn't make a lot of sense!). The horizontal speed (i.e. x and z components) was being scaled properly, but the vertical one wasn't.

I need to change how it all works anyway, as it isn't quite how I want it. I'd sort of got used to it before, but having to reconfigure the variables to take account for the new scaling made me realise that it could do with a reworking.
 

Blizzard

Banned
That feel when you realize someone did something that looks super similar 5 years ago for a different Ludum Dare, to the current thing you're making for Ludum Dare. :|
 

Jharp

Member
Hey guys! ULTRA-baby here, I just started working on my first game. A friend of mine is a programmer for a fitness company out here in California, and he's been coding since we were in junior high (we're both 24). We've been talking about doing a game together for ages, but never got on it until just a few weeks ago. I unfortunately never learned coding or anything actually useful, because I studied English in college. Because, you know, if you want to make games, why not read some fiction?

Anyways, he started giving me basic assignments on a weekly basis. First he wanted me to design a title screen, then a menu. The game we're making is Super Rock Paper Scissors, and I'm aiming for a Zelda-clone on a much smaller scale. Most recently, he assigned me to complete a walking animation cycle sprite sheet for the main character of my game. This is what I did:

The sprites I'm making are in in 48x64, and I'm making them with GIMP 2.8. I've used several sprites from other games as reference. My current assignment is to design three enemies, and this is all I've got so far: basic Rock enemy, a skeleton:

I'm thinking the basic enemy type for each faction will be skeleton-based, with Scissors being a Skeleton with blades for arms, and not sure what I'll do for paper. I'm hoping to have a full animation sheet (walking, attacking, dying) for at least one of the enemies done this week.

I'm also looking towards working on map design. I already have a general layout considered for the world, but nothing built. I'll begin tilesheet design at some point soon, hopefully. Let me know what you guys think, and any pertinent tools or tutorials you can recommend would be awesome. I'm only doing design work and asset creation, with my friend doing all the technical stuff. Not sure what language he's using, but he's loaded all my Menu stuff in and got my character and his walking animation in and controllable pretty easily.

As I said, I'm using GIMP 2.8 a LOT for art asset generation, and will likely use Tiled for my map design.
 
Aright, just rushed submit an iOS game before the May 1st deadline.

So, suggestions on what to do with the extra screen space when I have to do a new update and must support the iPhone 5 screen? I know I'm going to be in a world of hurt already when I need to migrate from cocos2d 1.0.1 to 1.1 AND move from iOS4 to iOS5 support.
 

Dynamite Shikoku

Congratulations, you really deserve it!
Aright, just rushed submit an iOS game before the May 1st deadline.

So, suggestions on what to do with the extra screen space when I have to do a new update and must support the iPhone 5 screen? I know I'm going to be in a world of hurt already when I need to migrate from cocos2d 1.0.1 to 1.1 AND move from iOS4 to iOS5 support.

Ouch. Why not take the opportunity to update to 2.0 or 2.1? Or are you supporting old devices?
My game uses a physics world based off the original size of the iPhone screen, so for widescreen I just added some walls on the sides. Probably not the nicest solution though.
 
Ouch. Why not take the opportunity to update to 2.0 or 2.1? Or are you supporting old devices?
My game uses a physics world based off the original size of the iPhone screen, so for widescreen I just added some walls on the sides. Probably not the nicest solution though.
Well, I could jump directly to 2.X, but I was assuming that there'd be less stuff for me to worry about with 1.X branch. My existing games all were supporting 4.0 (3G/Touch 2G_, but since this new "iPhone 5" requirement is kicking in, I'm pretty much forced to abandon armv6 devices now.

Yeah, the Walls solution is probably the easiest (and the approach I have used for handling supporting iPad/Universal conversions... Not sure how Apple will like it though, cause their wording is really weird.
 

Blizzard

Banned
Ugh, I feel like figuring out music licensing is the one of the hardest parts of ludum dare. What if you use a MIDI sequencer? Well, what legal issues are there with the standard Windows sound font? What if you use an online sequencer? What are the chances that they will actually have a clear license about whether you can use individual sound effects and music to export?

Even LMMS, a nice Linux/Windows sequencer, apparently has some sort of confusion about whether it is legal to use the samples as sound effects, and no answer. :(

It's almost as much of an obnoxious situation as trying to figure out whether particular fonts or uses of fonts are legal.
 

Blizzard

Banned
I ended up giving up quickly finding a definitive answer on the legal situation of various tools, and I couldn't even get my keyboard to record through an audio line though I've done it in the past. So I decided to just scrap any music or audio and upload what I had. It's just a Mondrian doodle program. It probably took me 12-18 hours which is way too long for what it is, but that's the way things go when I try to do anything, especially if the tool isn't super familiar.

screenshot1lqu2l.png


https://dl.dropboxusercontent.com/u/55797038/mondricraft/index.html

Link including source: http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=12278
 
I ended up giving up quickly finding a definitive answer on the legal situation of various tools, and I couldn't even get my keyboard to record through an audio line though I've done it in the past. So I decided to just scrap an music or audio and upload what I had. It's just a Mondrian doodle program. It probably took me 12-18 hours which is way too long for what it is, but that's the way things go when I try to do anything, especially if the tool isn't super familiar.
Oh man, that's super rad. What tool did you use?

Edit: nevermind, saw it at the link. Love the idea so much though.
 

Anustart

Member
A little peak at what my final project in Uni is looking like.

The style is heavily influenced from World of Goo, but with some differences, and all the art is original, proud of this one.

Presenting My Little Gluon

IYWGWfj.png


My little ball graphic isn't final, just some programmer art thrown in. All my gravity switching is functional, just need to build levels, obstacles, gui, etc.
 

Dusk Golem

A 21st Century Rockefeller

Feep

Banned
So, partially thanks to everyone's help, my partner and I won best game And best educational tool at AngelHack LA! Took home a thousand bucks between us. :) Thanks again!
 
A screenshot from the horror game I've been making with Unity.
I love this engine! It allows really fast iterations and it's very fast to use.

I've at tried to do Gamma Calibration for my screen, so hopefully it isn't too dark or too bright.

Thats looking really good....are you using the full version of Unity?

Im also loving Unity, saving up for the full version for dynamic shadows and post-processing effects.
 

Blizzard

Banned
So, partially thanks to everyone's help, my partner and I won best game And best educational tool at AngelHack LA! Took home a thousand bucks between us. :) Thanks again!
You're dividing the check up between the 50 of us posting in this thread so we all share the result, right? ;p Congrats.

Oh man, that's super rad. What tool did you use?

Edit: nevermind, saw it at the link. Love the idea so much though.
Hey thanks, you're very kind! I like the idea of Flixel for simple 2D web games, I just always run into issues. I also feel like I should really nail down a legal free distribution audio + music system if I try something like ludum dare again. Or at the very least double check that my keyboard cable record setup works. =P
 

omg_mjd

Member
Finally finished my first game ever! It's a pretty damn simple 2D game but I did do everything from scratch (in Construct 2) so I'm feeling kinda good about it. I'm glad Ludum Dare was around to motivate me into finishing something.

So here's my LD 26 entry ("Untitled"): http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=22245

HTML5: http://db.tt/ttfqul0C

EDIT: Thanks for the feedback, Blizzard! I'll give other color schemes a try.

 

Anustart

Member
So, in Unity is there a way to flush a scene from memory? If my player dies and I just Application.LoadLevel back into the same one, the objects don't reset.

And also, if I'm having my music run from an object, how can I keep this music playing between scenes and NOT have it create another one on LoadLevel? Right now I have a DontDestroyOnLoad(myMusic);

But when I load level again, another music is created and I get two of the same song playing.
 

usea

Member
I ended up giving up quickly finding a definitive answer on the legal situation of various tools, and I couldn't even get my keyboard to record through an audio line though I've done it in the past. So I decided to just scrap any music or audio and upload what I had. It's just a Mondrian doodle program. It probably took me 12-18 hours which is way too long for what it is, but that's the way things go when I try to do anything, especially if the tool isn't super familiar.

http://abload.de/img/screenshot1lqu2l.png

https://dl.dropboxusercontent.com/u/55797038/mondricraft/index.html

Link including source: http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=12278
Yes! Pretty cool doodler. The results are great.

So, partially thanks to everyone's help, my partner and I won best game And best educational tool at AngelHack LA! Took home a thousand bucks between us. :) Thanks again!
Congrats.
 

MrOddbird

Neo Member
That looks neat. Can I ask you if that cave was built as a single object or with many modular parts?

Thanks!

I'm using a couple of cave wall parts in this scene, so yeah it is modular.
I had a big problem creating the right parts that fit together, because sometimes they would just overlap. So I've tried to learn a few techniques to make the caves look a bit more natural.

Thats looking really good....are you using the full version of Unity?

Im also loving Unity, saving up for the full version for dynamic shadows and post-processing effects.

Thank you!

The game is made entirely on Unity Free.
I can only imagine how good the game would look with dynamic shadows and post-pros. effects applied.

Anyway, lighting and good normal maps take you a long way.
The scene is pretty dark (I actually don't use Unity's ambient light) and some of the walls look much more detailed than they actually are.

I use a single 512x512 texture on the walls and for parts that are closer to the player, I tile the texture and try to hide some of the repetition with rocks and other props.
 

Blizzard

Banned
I played 4 games on easy and got destroyed every time.
Yeah, I found you had to get the advantage on the first or second turn in removing red pieces, or else you're done for.

This one has adorable sprite art:
http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=4268

Well done audio and polish, WASD controls:
http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=22003

Pretty polished 2D block collecting game, kind of like Pacman meets VVVVVV or something:
http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=7958

Neat Conway's Game of Life type puzzle with music, sort of hard to explain, but worth checking out:
http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=22563

There does not seem to be much to do in this minimal Pokemon-esque game, but I love the clay art style:
http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=21063
 

Dascu

Member
So, in Unity is there a way to flush a scene from memory? If my player dies and I just Application.LoadLevel back into the same one, the objects don't reset.

And also, if I'm having my music run from an object, how can I keep this music playing between scenes and NOT have it create another one on LoadLevel? Right now I have a DontDestroyOnLoad(myMusic);

But when I load level again, another music is created and I get two of the same song playing.

The first issue is odd, normally LoadLevel resets everything.
As for your music, add a script (or add to it if there already is one) for myMusic, making sure to destroy itself if another object already exists. To see which object is oldest, perhaps put in a variable that changes value at Start.

e.g.
Code:
function Start () { 

if <find another object with the same name or tag>
if other.GetComponent(music_script).hasBeenLoadedBefore == true { Destroy(gameObject); }

hasBeenLoadedBefore = true;

}
 

Tiu Neo

Member
Ugh, my day job and my personal life are getting in the way, I hardly worked on any games last two weeks. Got a lot of ideas, too.

Missed Ludum Dare, too, but for a good reason: I started a game development postgrad degree :) It was pretty cool, meeting other local developers and developer wannabes like me.
 

GulAtiCa

Member
Spent an hour or so with a Tutorial yesterday getting used to the Unity editor and all it can do/etc. Also spent some time looking at the code for UnityScript. Starting to get a feel for how things happen in Unity.
 

JulianImp

Member
So, in Unity is there a way to flush a scene from memory? If my player dies and I just Application.LoadLevel back into the same one, the objects don't reset.

That's odd. Application.LoadLevel set to the current level should restart everything, unless your objects are static or have DontDestroyOnLoad active.

And also, if I'm having my music run from an object, how can I keep this music playing between scenes and NOT have it create another one on LoadLevel? Right now I have a DontDestroyOnLoad(myMusic);

But when I load level again, another music is created and I get two of the same song playing

Here's a classes I used to do what you want, with the added trick of cross-fading between tracks on a transition (coded in C#):
Code:
using UnityEngine;
using System.Collections;

public class MusicControl : MonoBehaviour {
	
	static public MusicControl instance;
	
	public  AudioSource audioSource1;
	public  AudioSource audioSource2;
	private AudioSource currentAudioSource;
	private AudioSource previousAudioSource;
	
	public  float crossFadeTime = 2;
	private float crossFadeCounter;
	private bool  crossFading = false;
	
	private void Awake() {
		if (instance== null) instance= this;
		else {
			GameObject.Destroy(this.gameObject);
			return;
		}
		GameObject.DontDestroyOnLoad(this.gameObject);
		currentAudioSource= audioSource1;
	}
	
	public void PlayClip(AudioClip newClip) {
		if (currentAudioSource.clip != null) {
			if (currentAudioSource.clip == newClip) return;
			
			if (currentAudioSource == audioSource1) {
				currentAudioSource   = audioSource2;
				previousAudioSource = audioSource1;
			}
			else {
				currentAudioSource   = audioSource1;
				previousAudioSource = audioSource2;
			}
		}
		
		currentAudioSource.clip = newClip;
		currentAudioSource.Play();
		
		crossFadeCounter= 0;
		crossFading = true;
	}
	
	private void Update() {
		if (!crossFading ) return;
		
		currentAudioSource.volume = crossFadeCounter / crossFadeTime;
		
		if (previousAudioSource != null) {
			previousAudioSource.volume = 1 - crossFadeCounter / crossFadeTime;
		}
		
		if (crossFadeCounter < crossFadeTime ) {
			crossFadeCounter += Time.deltaTime;
			if (crossFadeCounter > crossFadeTime ) crossFadeCounter = crossFadeTime;
		}
		else {
			crossFadeCounter = 0;
			crossFading = false;
			previousAudioSource.Stop();
			previousAudioSource.clip = null;
		}
	}
}


You put the MusicControl class on an empty GameObject on your first scene, and whenever you want to play any specific clip, you simply call its PlayClip method with the AudioClip you want and the class will automatically crossfade into it as long as the clip isn't playing already. Here's an example of a component that requests a new track when a scene is first loaded and then destroys itself:
Code:
using UnityEngine;
using System.Collections;

public class MusicPlayer: MonoBehaviour {
	
	public AudioClip myAudioClip;
	
	private void Awake() {
		if (myAudioClip!= null) MusicControl .instance.PlayClip(myAudioClip);
		GameObject.Destroy(this.gameObject);
	}
}

There might be a few mistakes since I've just translated all class, method and property names from Spanish to English, so feel free to let me know if you find any issues with the code.
 

Anustart

Member
That's odd. Application.LoadLevel set to the current level should restart everything, unless your objects are static or have DontDestroyOnLoad active.



Here's a classes I used to do what you want, with the added trick of cross-fading between tracks on a transition (coded in C#):


Thanks a bunch! I'll implement this tonight and let you know how it goes!

Also, I do have some static variables in my scripts. I'll just re-code those and use some GetComponents instead of static, hopefully works after that!
 

JulianImp

Member
Thanks a bunch! I'll implement this tonight and let you know how it goes!

Also, I do have some static variables in my scripts. I'll just re-code those and use some GetComponents instead of static, hopefully works after that!

You could also make it so that all those static variables get re-initialized on each script's Awake event, like:
Code:
static private int someNumber;
private const int DEFAULT_NUMBER = 5;

private void Awake() {
    someNumber = DEFAULT_NUMBER;
    //The rest of the awake code goes here (if any)
}

By the way, you should probably encapsulate some of the public variables I set for the MusicControl class to avoid unauthorized changes to the variables like this:
Code:
using UnityEngine;
using System.Collections;

public class MusicControl : MonoBehaviour {
	
	static private MusicControl myInstance;
	
	[SerializeField] private AudioSource audioSource1;
	[SerializeField] private AudioSource audioSource2;
	private AudioSource currentAudioSource;
	private AudioSource previousAudioSource;
	
	[SerializeField] private float crossFadeTime = 2;
	private float crossFadeCounter;
	private bool  crossFading = false;
	
	static public MusicControl instance {
		get { return myInstance; }
	}
	
	private void Awake() {
		if (myInstance == null) myInstance = this;
		else {
			GameObject.Destroy(this.gameObject);
			return;
		}
		GameObject.DontDestroyOnLoad(this.gameObject);
		currentAudioSource = audioSource1;
	}
	
	public void PlayClip(AudioClip newClip, bool useCrossFade) {
		if (currentAudioSource.clip != null) {
			if (currentAudioSource.clip == newClip) return;
			
			if (useCrossFade) {
				if (currentAudioSource == audioSource1) {
					currentAudioSource   = audioSource2;
					previousAudioSource = audioSource1;
				}
				else {
					currentAudioSource   = audioSource1;
					previousAudioSource = audioSource2;
				}
				
				crossFadeCounter= 0;
				crossFading = true;
			}
		}
		
		currentAudioSource.clip = newClip;
		currentAudioSource.Play();
	}
	
	private void Update() {
		if (!crossFading ) return;
		
		currentAudioSource.volume = crossFadeCounter / crossFadeTime;
		
		if (previousAudioSource != null) {
			previousAudioSource.volume = 1 - crossFadeCounter / crossFadeTime;
		}
		
		if (crossFadeCounter < crossFadeTime ) {
			crossFadeCounter += Time.deltaTime;
			if (crossFadeCounter > crossFadeTime ) crossFadeCounter = crossFadeTime;
		}
		else {
			crossFadeCounter = 0;
			crossFading = false;
			previousAudioSource.Stop();
			previousAudioSource.clip = null;
		}
	}
}

The [SerializeField] property lets you edit private variables inside Unity's inspector without exposing them to other classes, as you would with public variables, and I encapsulated the object's instance, making it private and adding a public getter instead. I've also added a "useCrossFade" parameter too the method so you can just ask the player to stop the previous track and play the new one instead of doing a cross-fade.

To change a track, all you'd have to do is call the method from anywhere in your code like this:
Code:
MusicControl.instance.PlayClip(<someClip>, <crossFade>);
With <someClip> being the AudioClip you want to play and <crossFade> being a boolean that says whether you want to cross-fade the previous clip or not.
 

Anustart

Member
You could also make it so that all those static variables get re-initialized on each script's Awake event, like:

With <someClip> being the AudioClip you want to play and <crossFade> being a boolean that says whether you want to cross-fade the previous clip or not.

Question, where are audioSourceAnterior and audioSourceActual coming from?
 

JulianImp

Member
Question, where are audioSourceAnterior and audioSourceActual coming from?

Heh, that's some untranslated variables I forgot to change. "audioSourceAnterior" should be "previousAudioSource", and "audioSourceActual" should be "currentAudioSource". I'll modify my previous posts accordingly.
 
Status
Not open for further replies.
Top Bottom