Like if i click on a fridge door and it opens, or click on a chest and the top slides off.
Add a ClickDetector inside of it, and add a script that does what you want to do. To open it sideways you can do this:(It might not turn the right way)
for i = 1, 90 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi*90/1, 0)
wait()
end
Add a clickdetector, and script it so onclick the parent part moves from one place to another.
Related
Cars are moving on the road, and I want to use a button to change the scale of the cars.
Once I press the button, the scale of all the cars that are in the system and are being produced by the source should change.
My approach
1. I make a variable "carSize" and put it in "car" 3Objact properties "Additional Scale." shown in image below.
2 Then in "Main" I put this code in a button.
LineCarAgent LineCar = new LineCarAgent();
LineCar.set_carSize(11);
traceln("New car size " + LineCar.carSize);
Now, when I run the model and press the button, I can see the new value printed in the console, but the size of the car does not change, neither for existing cars nor for upcoming cars.
If you know which car you want to have the shape scale change, use:
cars.get(i).car.setScale(s);
We can use a loop to go through "cars" population and change the scale of all the cars one by one.
The only issue is that if we include "loop" in the button, then only the scale of the existing population will change. So what we can do is put the loop in the cyclic event to keep changing the scale of the new coming car.
Step 1: Create an cyclic event and put this code in the action
for (int i = 0; i < cars.size(); i++) {
cars.get(i).car.setScale(0.9);
}
Step 2: We don't want the code in the event to start executing unless we press the button, so "on startup" write event.suspend(); and in the button action, write event.restart();.
Now event will only start once we press the button. Which means that all the cars scale will only change when we press the button.
I am writing a Custom Editor in Unity - at present I can just drag some points around and the editor draws a line between them all.
I have implemented pressing Shift-Click to add a new point, and this works fine - except...
If I press shift, then click , my new point appears.
If I release shift, then release the mouse button, all is well.
If I release the mouse button first though, the game object that was highlighted (and contains all of my points) loses focus - nothing in the hierarchy has focus - so I lose my handles and the editor is no longer active.
Some of the relevant code
if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 && guiEvent.shift)
{
var pos = GetMousePositionOnXYPlane(mouseRay);
var cp = new ControlPoint(ControlPointType.Flat);
cp.Positions.Add(pos);
level.AddControlPoint(cp);
}
I have tried adding
Selection.activeGameObject = _level.gameObject;
immediately after the adding of the control point, to no avail.
If I use Shift / right-click focus is not lost
If I use just Left Click, focus is not lost.
I'm at a loss what to try next...
I have a listview and a rectangle on top of it. The ListView's delegates have DropAreas in them and the rectangle has drag enabled on Y axis with its relevant properties (hotspot, target).
When I move the rectangle up and down on the ListView, the DropAreas of the delegates are registering onEntered signals. Working as intended.
However, I am using SmoothedAnimation to scroll the list up and down when the rectangle is at the most top and bottom coordinates (list.y = 0 and list.height). So the rectangle is not moving, and the DropAreas of the list's delegates are moving under it. In that case, the onEntered is not registered because there is no dragging, the rectangle is completely still and although its hotspot is entering and leaving the DropAreas, there is no interaction.
This is because dragging mechanic is sending events all the time when moving and any DropAreas it comes inside can register the event. In my case there is no dragging and therefore no events.
Question: Can drag events be manually activated? Can I somehow simulate drag?
At first, you should change the drag.target: parent to drag.target: this. In this way instead of dragging the parent item, you drag only the mouseArea. After that, you should grab an image from the item that you want to drag. The code is here:
Rectangle {
id: rec
width: 100
height: 100
Drag.active: dragArea.drag.active
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
MouseArea {
id: dragArea
anchors.fill: parent
drag.target: this
onPressed:{
parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
})
}
}
}
I have managed to induce drag events by manually changing the hotSpot property of the rectangle above the list. QML Drag documentation says:
Changes to hotSpot trigger a new drag move with the updated position.
So I have done this every time Listview contentY changes (vertical scrolling happens)
onContentYChanged:
{
rectangle.Drag.hotSpot.x += 0.0001
rectangle.Drag.hotSpot.x -= 0.0001
}
In hindsight, however, this is a 'hacky' solution. hotSpot property is a QPointF class property (link). This means it can be set using various methods (setX, setY, rx, ry..). For example, this:
rectangle.hotSpot += Qt.point(0,0)
or
rectangle.hotSpot = Qt.point(rectangle.hotSpot.x,rectangle.hotSpot.y)
should work in theory by resetting the hotSpot point when contentY changes, but testing revealed it unfortunately does not trigger a new drag move. (bug or intended, I don't know)
Now some of you that are more into Qt and QML might know more about this and how to properly adress the issue, but the above solution works for me and after testing everything I could imagine to get a cleaner solution, I settled on it.
i have a 2d platformer with a player. The players default sprite is set to idle. There is 4 sprites and states in total --> idle, jumping, left, right.
Im trying to get the player to switch sprites depending on what their doing eg jumping or moving right.
This is my first time using unity and animator so im not experienced at all.
So each of my animations look something like this. 1 frame and one for each state:
And then I open up the animator:
Im not too sure what the arrows do but i figured its like a flow chart so you go from idle to left so i matched up the arrows. I then also made 4 booleans for each state.
Then on the script attached to the player, i added this code:
private Animator animator;
void Start () {
animator = GetComponent<Animator>();
}
//This is in the update function
if (!playerLeft && !playerRight && !jumping)
{
setAnimationState("playerIdle");
}
else if (jumping)
{
setAnimationState("playerJumping");
}
}
private void setAnimationState(String state){
animator.SetBool("playerJumping", false);
animator.SetBool("playerLeft", false);
animator.SetBool("playerRight", false);
animator.SetBool("playerIdle", false);
animator.SetBool(state, true);
}
So i made a function that cancels of the animations and switches it to the correct one which is called. You can see how i call it with jumping and i also have the same for left and right but i know they are all being called correctly from the animator.
In the animator, only the right grey box is running. I can see because it has a blue bar and its not switching animations. The booleans are switching but thats it.
On the top of my head:
You need a transition from right to left and left to right.
You need one from right, left and jumping back to idle.
You can click on the arrows and select which booleans need to be checked to enable the transition.
Fore each animation state you need to upload a spritesheet. You can drag and drop this in the animation tab. The animation will play untill there are no more sprites. It will then check if it can transition into another state or loop the current state. (Do note that you need to enable looping on each state, except jumping i guess?)
Welcome to Unity development :)
I don't want to make this too long, so let's just use playerLeft as an example.
So you've set the Idle state as the default state - meaning if all the booleans are false, the player is idle. But once you press the left key, you would want the player to transition from the idle state to the Left state.
First step is to click on the transition (the arrow) from idle to playerLeft.
Next, is to add the playerLeft boolean as the condition. This means that when the playerLeft boolean becomes true, we start transitioning from Idle to Left.
And finally, tinker with the code. We need to tell Unity to set playerLeft to true when we press the "D" button for example.
Update()
{
if(Input.GetKeyDown(KeyCode.D))
animator.SetBool("playerLeft",true);
}
We place it in the Update() method to make sure it runs every frame. Then, we have a condition where it waits for the player to press D.
There's still a whole lot to do after this such as doing return transitions but well, you'll figure out the rest as you go so don't hesitate to ask ;)
I have two forms, frmPE and frmCRE. They are modal.
frmCRE has a button "Edit PE" that will open formPE (instance of frmPE).
If I don't play with the positions, formPE opens centered on top of frmCRE.
I would like to position them side by side so I can see both at once.
When I open frmPE, I can still see frmCRE but not touch it. That's OK.
' This code is in cmdEditPE
Set formPE = New frmPE
Load formPE
If Not formPE.bInitialize(vbFalse) Then Err.Raise glHANDLED_ERROR
Me.Left = 100 ' move frmCRE to the left so I can see it
formPE.Left = Me.Left + Me.Width ' move frmPE to move to the right side of frmCRE (bad)
formPE.Show
I think the problem is that when formPE opens, it uses its default left setting. From within PE, I can see that me.Left = 0 even though it was set before the show.
Is there a way I can use the formPE.bInitialize routine to see that frmCRE is open and find out its LEFT and WIDTH so I can set formPE.Left correctly, or a way I can set it from frmCRE as I was trying to do above?
Thanks
Shari
Use the Activae event of frmPE to move itself, but only if frmCRE is visible.
In frmPE
Private Sub UserForm_Activate()
If frmCRE.Visible Then
Me.Left = frmCRE.Left + frmCRE.Width
End If
End Sub