Handle it just the way you handled it yesterday! You did well! Acknowledge his feelings just the way you did. And it's fine to play along and acknowledge the feelings of his truck and car, too. Don't overdo it or drag it out on your part, but do acknowledge and offer that hug. He did clearly want you to participate in his play and give those hugs and strokes, and that's great. Don't dismiss him or tell him "Oh, you know the truck can't be sad!" He does know that on some level already, but it's fine to play his game as you describe it.
Kids his age are learning about their own feelings and at the same time learning to imagine things so vividly. It's very normal for a child his age to assign "feelings" to toys or even other objects, and to empathize with those toys or objects. Sometimes a kid is assigning his own real feelings to the things, or he might simply be pretending. The fact that he moved on with his play indicates he's just fine. You may find this happens again, maybe many times, but it's normal.
Not sure why the idea that he's an only child enters into things -- Are you noting that fact just to indicate you don't have previous experience of this, or noting it out of some concern that this behavior is related to his being an only child? If the reason is concern: It's behavior that kids sometimes do (and some kids don't) -- regardless of only child status, or being one of several. I too have an only child (13 now) and have seen this kind of play-acting in kids who had siblings too. So if the reason for mentioning his only-child status is concern that it's somehow negatively "causing" him to do this, don't worry about that.