Simple stuff to do, don't know syntax... can someone "translate" ? (T_T)

Hello,

I want to do very simple stuff but I don’t know anything about the syntax. Unity’s Script Reference is made for people who has a background in programming. When you don’t have such a background, it’s like reading an Italian dictionary about Russian: It doesn’t make any more sense.

Well, I’ve been stuck with this problem for 3 days now because I could not find anything that helped me progress.

I’m doing a 2D block puzzle game where you can only drag on the X axis. What I want to do is when I click on a block, check where are the next blocks on the left and right and say to the block “you can’t move further here or there”.

So here is my “code” (it’s not real code):

function OnMouseDown(){
	if(Raycast.Physics on the right collides with next collider){
		read next collider x position	
		maxXPos = Mathf.Clamp(nextColliderXposition)
	}
	if(Raycast.Physics on the left collides with previous collider){
		read previous collider x position	
		minXPos = Mathf.Clamp(previousColliderXposition)
	}	
	Print("Min X = " + previousColliderXposition + "; Max X = " + nextColliderXposition); 
}

Can someone help me write this in proper code ? Is my logic alright ? I’m exhausted…

Thank you very much…
Phil

actually, it’s not made for people who can already do it, when i started, I diddn’t understand it, but I learned from it, and now it makes sense.

anyway, function OnMouseDown is called when you click down on a collider, that’s probably not what you want

what exactly is it you want?

I did a simple package according to what you said. So try it yourself and read from the scripting reference.
It’s Physics.Raycast not the other way round. Unity - Scripting API: Physics.Raycast

643949–23024–$puzzles.unitypackage (8.59 KB)

Hello! Thanks for your reply!

What I want to do is this:
The goal of the game is to slide panels using the mouse but you can only slide on the X axis. The game screen is 6 panels wide and about 10 high. It’s a bit like Tetris Attack or Panel de Pon in Japan (or Planet Puzzle League: http://www.youtube.com/watch?v=bwndmHg6itg&feature=related ) if you ever played it. But my version is a bit different: the panels don’t switch positions when you drag them around. Instead, some panels are colliding which means you cannot drag the panel further unless some conditions are met. For example, if you slide a red panel toward another red panel then release the mouse button, they will merge and clear.

So before you actually start to drag the panel around, I want tell that panel in advance (when clicking on it just before dragging) that it cannot move further on the left or on the right, depending on which color the neighbor is. So I want to cast a Ray on left and right then tell to that panel: this is the min / max X position you are allowed to be slid.

Thank you so much for helping me out!! :slight_smile:

P.S: I’m also VERY visual so is it possible to cast a visible ray that matches exactly the one I’m testing ? I know Debug.Ray exists but is it easy to tell it: Show me that ray I’m already using (instead of having to enter other parameters) ?

Thanks!! I’ve checked your package. Can I use Vector2 instead of Vector3 ? I changed it and nothing seems to be happening now. Also, can the “hitDistance” be an integer ? I try not to use float because I want pixel-perfect 2D translations and operations.

That is why I’m confused all the time. I just changed stuff that for me would make sense: changing Vector3 to Vector2 and float to int and everything is broken. Why doesn’t it just work ? :slight_smile:

EDIT: Is there any UnityScript paperback manual I can buy somewhere ?